Module: RedisRecord::Base::ClassMethods

Defined in:
lib/redis_record/base/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#create(*args) ⇒ Object



13
14
15
# File 'lib/redis_record/base/class_methods.rb', line 13

def create(*args)
  new(*args).save
end

#create_filter(name, &block) ⇒ Object



26
27
28
# File 'lib/redis_record/base/class_methods.rb', line 26

def create_filter(name, &block)
  self.defined_filters = self.defined_filters.merge name.to_sym => block
end

#filter_key(name, value) ⇒ Object



42
43
44
# File 'lib/redis_record/base/class_methods.rb', line 42

def filter_key(name, value)
  meta_key "Filter:#{name}:#{value}"
end

#find(id) ⇒ Object



17
18
19
# File 'lib/redis_record/base/class_methods.rb', line 17

def find(id)
  find_by_key key id
end

#find_or_initialize_by_id(id) ⇒ Object



22
23
24
# File 'lib/redis_record/base/class_methods.rb', line 22

def find_or_initialize_by_id(id)
  find(id) || self.new(:id => id)
end

#key(id) ⇒ Object



46
47
48
# File 'lib/redis_record/base/class_methods.rb', line 46

def key(id)
  [model_name, id].join ':'
end

#meta_key(attr) ⇒ Object



38
39
40
# File 'lib/redis_record/base/class_methods.rb', line 38

def meta_key(attr)
  ['Meta', model_name, attr].join ':'
end

#scoped(*args) ⇒ Object



6
7
8
# File 'lib/redis_record/base/class_methods.rb', line 6

def scoped(*args)
  RedisScope.new self, *args
end

#sortable(name, &block) ⇒ Object



30
31
32
# File 'lib/redis_record/base/class_methods.rb', line 30

def sortable(name, &block)
  self.defined_sorts = self.defined_sorts.merge name.to_sym => block
end

#values_for_filter(name) ⇒ Object



34
35
36
# File 'lib/redis_record/base/class_methods.rb', line 34

def values_for_filter(name)
  RedisRecord.REDIS.zrange filter_key('_Values', name), 0, -1
end