31 lines
567 B
Ruby
31 lines
567 B
Ruby
class ApplicationService
|
|
include Callable
|
|
|
|
Error = Class.new(StandardError)
|
|
|
|
def regix_emoji content
|
|
" " if content.blank?
|
|
regex = /[^a-zA-Z0-9\u4E00-\u9FFF]/
|
|
content.gsub(regex, '')
|
|
end
|
|
|
|
protected
|
|
def try_lock(key)
|
|
raise Error, "请稍后再试!" unless $redis_cache.set(key, 1, nx: true, ex: 60.seconds)
|
|
end
|
|
|
|
def unlock(key)
|
|
$redis_cache.del(key)
|
|
end
|
|
|
|
private
|
|
|
|
def strip(str)
|
|
str.to_s.strip.presence
|
|
end
|
|
|
|
def str_to_boolean str
|
|
ActiveModel::Type::Boolean.new.cast str
|
|
end
|
|
end
|