Module: Redis::Objects::RMap::ClassMethods
- Defined in:
- lib/redis/objects/rmap.rb
Instance Method Summary collapse
Instance Method Details
#has_rmap(title = nil, id = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/redis/objects/rmap.rb', line 24 def has_rmap(title=nil, id=nil) if title.is_a?(Hash) && title.length > 1 id = {title.keys[1] => title.values[1]} end = { :title => title, :id => id || :id }.with_indifferent_access raise "title can not be blank" if [:title].blank? self. = {}.with_indifferent_access %w(id title).each do |x| if [x].is_a?(Hash) self.["#{x}_field"] = [x].keys[0].to_sym self.["#{x}_proc"] = [x].values[0] else self.["#{x}_field"] = [x].to_sym self.["#{x}_proc"] = nil end end end |
#rmap ⇒ Object
70 71 72 |
# File 'lib/redis/objects/rmap.rb', line 70 def rmap rmap_storage.value || rmap_cache end |
#rmap_cache ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/redis/objects/rmap.rb', line 49 def rmap_cache models = self.select([[:id_field], [:title_field]]).map do |a| data = [] %w(id title).each do |x| value = a.send(["#{x}_field"]) value = ["#{x}_proc"].call(value) unless ["#{x}_proc"].blank? data << value end data end self.rmap_storage = Hash[*models.flatten] end |
#rmap_clear ⇒ Object
66 67 68 |
# File 'lib/redis/objects/rmap.rb', line 66 def rmap_clear self.rmap_storage = nil end |