module Devise::Models::Onlineable::ClassMethods

Attributes

time_opts[R]

Public Instance Methods

get_time_opts() click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

time(opts={}) click to toggle source
# File lib/onlineable/model.rb, line 41
def time(opts={})
  @time_opts = opts
end