Sha256: 64d4b2a4860e33c5ada12ffc2c10f46bc7275d1ff88976448a44bdc97244755b

Contents?: true

Size: 1.07 KB

Versions: 102

Compression:

Stored size: 1.07 KB

Contents

ActiveRecord::Base.class_eval do
  def stream
    Nest.new(self.class.name, $redis)[to_param]
  rescue
    nil
  end

  def self.stream
    Nest.new(name, $redis)
  rescue
    nil
  end

  def events(size=-1)
    stream[:event].lrange(0, size).map do |event_id|
      {
        action: $redis.hget("events:#{event_id}", "action"),
        timestamp: $redis.hget("events:#{event_id}", "timestamp")
      }
    end
  rescue
    []
  end

  def profile_events(size=-1)
    stream[:event][:profile].lrange(0, size).map do |event_id|
      {
        action: $redis.hget("events:#{event_id}", "action"),
        timestamp: $redis.hget("events:#{event_id}", "timestamp")
      }
    end
  rescue
    []
  end

  def create_event(action, timestamp)
    event_id = $redis.incr("events:latest_id")
    $redis.hmset("events:#{event_id}", "action", action, "timestamp", timestamp)
    event_id
  rescue
    nil
  end

  def log_event(event_id)
    stream[:event].lpush(event_id)
  rescue
    nil
  end

  def log_profile_event(event_id)
    stream[:event][:profile].lpush(event_id)
  rescue
    nil
  end
end

Version data entries

102 entries across 102 versions & 2 rubygems

Version Path
sufia-models-6.2.0 lib/sufia/models/active_record/redis.rb
sufia-models-6.1.0 lib/sufia/models/active_record/redis.rb
sufia-5.0.0 sufia-models/lib/sufia/models/active_record/redis.rb
sufia-models-5.0.0 lib/sufia/models/active_record/redis.rb
sufia-models-6.0.0 lib/sufia/models/active_record/redis.rb
sufia-6.0.0 sufia-models/lib/sufia/models/active_record/redis.rb
sufia-6.0.0.rc4 sufia-models/lib/sufia/models/active_record/redis.rb
sufia-models-6.0.0.rc4 lib/sufia/models/active_record/redis.rb
sufia-6.0.0.rc3 sufia-models/lib/sufia/models/active_record/redis.rb
sufia-models-6.0.0.rc3 lib/sufia/models/active_record/redis.rb
sufia-5.0.0.rc1 sufia-models/lib/sufia/models/active_record/redis.rb
sufia-models-5.0.0.rc1 lib/sufia/models/active_record/redis.rb
sufia-6.0.0.rc2 sufia-models/lib/sufia/models/active_record/redis.rb
sufia-models-6.0.0.rc2 lib/sufia/models/active_record/redis.rb
sufia-6.0.0.rc1 sufia-models/lib/sufia/models/active_record/redis.rb
sufia-models-6.0.0.rc1 lib/sufia/models/active_record/redis.rb
sufia-4.3.1 sufia-models/lib/sufia/models/active_record/redis.rb
sufia-models-4.3.1 lib/sufia/models/active_record/redis.rb
sufia-6.0.0.beta1 sufia-models/lib/sufia/models/active_record/redis.rb
sufia-models-6.0.0.beta1 lib/sufia/models/active_record/redis.rb