Module: ActivePStore::FinderMethods
- Included in:
- Base
- Defined in:
- lib/active_pstore/finder_methods.rb
Instance Method Summary collapse
- #find(*ids) ⇒ Object
- #find_by(conditions = {}) ⇒ Object
- #find_by!(conditions = {}) ⇒ Object
- #first ⇒ Object
- #last ⇒ Object
- #take(limit = nil) ⇒ Object
Instance Method Details
#find(*ids) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/active_pstore/finder_methods.rb', line 3 def find(*ids) ids = ids.map {|id| id.is_a?(ActivePStore::Base) ? id.id : id } _find(*ids).tap do |ret| if ids.size == 1 raise ActivePStore::RecordNotFound, "Couldn't find #{self} with 'id'=#{ids.first}" if ret.nil? else raise ActivePStore::RecordNotFound, "Couldn't find all #{self} with 'id': (#{ids.join(', ')}) (found #{ret.size} results, but was looking for #{ids.size})" unless ret.size == ids.size end end end |
#find_by(conditions = {}) ⇒ Object
15 16 17 |
# File 'lib/active_pstore/finder_methods.rb', line 15 def find_by(conditions = {}) where(conditions).first end |
#find_by!(conditions = {}) ⇒ Object
19 20 21 |
# File 'lib/active_pstore/finder_methods.rb', line 19 def find_by!(conditions = {}) find_by(conditions) || (raise ActivePStore::RecordNotFound, "Couldn't find #{self} with conditions=#{conditions}") end |
#first ⇒ Object
23 24 25 |
# File 'lib/active_pstore/finder_methods.rb', line 23 def first all.first end |
#last ⇒ Object
27 28 29 |
# File 'lib/active_pstore/finder_methods.rb', line 27 def last all.last end |
#take(limit = nil) ⇒ Object
31 32 33 |
# File 'lib/active_pstore/finder_methods.rb', line 31 def take(limit = nil) limit ? all.take(limit) : first end |