Module: Redpear::Model::Finders::ClassMethods
- Defined in:
- lib/redpear/model/finders.rb
Instance Method Summary collapse
-
#all ⇒ Array<Redpear::Model>
All records.
-
#count ⇒ Integer
The number of total records.
-
#exists?(id) ⇒ Boolean
True or false.
-
#find(id) ⇒ Redpear::Model
A record, or nil when not found.
- #find_each {|record| ... } ⇒ Object
Instance Method Details
#all ⇒ Array<Redpear::Model>
Returns all records.
24 25 26 |
# File 'lib/redpear/model/finders.rb', line 24 def all members.map &method(:find) end |
#count ⇒ Integer
Returns the number of total records.
7 8 9 |
# File 'lib/redpear/model/finders.rb', line 7 def count members.size end |
#exists?(id) ⇒ Boolean
Returns true or false.
13 14 15 |
# File 'lib/redpear/model/finders.rb', line 13 def exists?(id) !id.nil? && members.include?(id) end |
#find(id) ⇒ Redpear::Model
Returns a record, or nil when not found.
19 20 21 |
# File 'lib/redpear/model/finders.rb', line 19 def find(id) instantiate(id) if exists?(id) end |
#find_each {|record| ... } ⇒ Object
30 31 32 33 34 |
# File 'lib/redpear/model/finders.rb', line 30 def find_each members.each do |id| yield find(id) end end |