Module: Modis::Finder::ClassMethods
- Defined in:
- lib/modis/finder.rb
Instance Method Summary collapse
Instance Method Details
#all ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/modis/finder.rb', line 15 def all records = [] Modis.with_connection do |redis| ids = redis.smembers(key_for(:all)) records = redis.pipelined do ids.map { |id| record_for(redis, id) } end end records.map do |record| attributes = record_to_attributes(record) model_for(attributes) end end |
#attributes_for(redis, id) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/modis/finder.rb', line 31 def attributes_for(redis, id) raise RecordNotFound, "Couldn't find #{name} without an ID" if id.nil? attributes = record_to_attributes(record_for(redis, id)) unless attributes['id'].present? raise RecordNotFound, "Couldn't find #{name} with id=#{id}" end attributes end |
#find(id) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/modis/finder.rb', line 8 def find(id) Modis.with_connection do |redis| attributes = attributes_for(redis, id) model_for(attributes) end end |