Module: Redify::Model::ClassMethods
- Defined in:
- lib/redify/model.rb
Instance Attribute Summary collapse
- #redify_handler ⇒ Object
-
#redify_keys ⇒ Object
Returns the value of attribute redify_keys.
Instance Method Summary collapse
Instance Attribute Details
#redify_handler ⇒ Object
10 11 12 |
# File 'lib/redify/model.rb', line 10 def redify_handler @redify_handler || Redify::Settings.default_handler end |
#redify_keys ⇒ Object
Returns the value of attribute redify_keys.
8 9 10 |
# File 'lib/redify/model.rb', line 8 def redify_keys @redify_keys end |
Instance Method Details
#all(*args) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/redify/model.rb', line 44 def all (*args) records = [] redify_handler.lrange(redify_keys[:all], 0, -1).each do |record_id| records << Redify::Core.fetch_record(:resource => self, :id => record_id) end records end |
#find(*args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/redify/model.rb', line 15 def find (*args) if args.size > 0 && args.last.is_a?(Hash) # let ActiveRecord deal with queries with extended options, including :skip_redify args.last.delete(:skip_redify) return super(*args) end a = args.at(0) return send(a) if a == :first || a == :last || a == :all records = [] args.each do |id| records << Redify::Core.fetch_record(:resource => self, :id => id) end args.size == 1 ? records.first : records end |
#first(*args) ⇒ Object
36 37 38 |
# File 'lib/redify/model.rb', line 36 def first (*args) Redify::Core.fetch_records_by_edge(self, false, args.first) end |
#last(*args) ⇒ Object
40 41 42 |
# File 'lib/redify/model.rb', line 40 def last (*args) Redify::Core.fetch_records_by_edge(self, true, args.first) end |