Module: Rediline::Object

Defined in:
lib/rediline/object.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(model) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rediline/object.rb', line 4

def self.included(model)
  model.send(:extend, ClassMethods)
  
  model.class_eval do
    private
    def rediline_key(field_name, entry, type, user=nil)
      raise "no entry provided" if entry.nil?
      user = entry.user if user.nil?
      "#{field_name.to_s}:#{user.class.to_s}.#{user.id.to_s}:#{type}"
    end

    def rediline_insert!(entry, key)
      Rediline.redis.del(key) unless Rediline.redis.type(key) == 'list'
      Rediline.redis.rpush(key, entry.to_json)
    end
  end
end