Module: Devise::Models::Onlineable::ClassMethods
- Defined in:
- lib/onlineable/model.rb
Instance Attribute Summary collapse
-
#time_opts ⇒ Object
readonly
Returns the value of attribute time_opts.
Instance Method Summary collapse
Instance Attribute Details
#time_opts ⇒ Object (readonly)
Returns the value of attribute time_opts.
6 7 8 |
# File 'lib/onlineable/model.rb', line 6 def time_opts @time_opts end |
Instance Method Details
#get_time_opts ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/onlineable/model.rb', line 30 def get_time_opts if self.time_opts.blank? opts = {seconds: 30} elsif self.time_opts.present? opts = self.time_opts end opts || {} end |
#who_online(time_def = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/onlineable/model.rb', line 8 def who_online(time_def=nil) opts = get_time_opts if time_def time = time_def else time = opts[:seconds].present? ? opts[:seconds].to_i : opts[:minutes].to_i end if defined?(REDIS) array_ids = [] online_array = REDIS.hgetall "o_#{self.to_s.downcase.pluralize}" online_array.each do |k, v| seconds_diff = (Time.now - v.to_time).to_i.abs if (opts[:seconds].present? && (seconds_diff <= time)) || (opts[:minutes].present? && ((seconds_diff / 60) <= time)) || (Time.now - v.to_time <= time) array_ids << k end end self.find( array_ids ) end end |