Module: ActivePStore::FinderMethods
- Included in:
- Base
- Defined in:
- lib/active_pstore/finder_methods.rb
Instance Method Summary collapse
- #find(id) ⇒ Object
- #find_by(conditions = {}) ⇒ Object
- #find_by!(conditions = {}) ⇒ Object
- #first ⇒ Object
- #last ⇒ Object
- #take(limit = nil) ⇒ Object
Instance Method Details
#find(id) ⇒ Object
3 4 5 6 7 |
# File 'lib/active_pstore/finder_methods.rb', line 3 def find(id) id = id.is_a?(ActivePStore::Base) ? id.id : id all.find {|obj| obj.id == id } || (raise ActivePStore::RecordNotFound, "Couldn't find #{self} with 'id'=#{id}") end |
#find_by(conditions = {}) ⇒ Object
9 10 11 |
# File 'lib/active_pstore/finder_methods.rb', line 9 def find_by(conditions = {}) where(conditions).first end |
#find_by!(conditions = {}) ⇒ Object
13 14 15 |
# File 'lib/active_pstore/finder_methods.rb', line 13 def find_by!(conditions = {}) find_by(conditions) || (raise ActivePStore::RecordNotFound, "Couldn't find #{self} with conditions=#{conditions}") end |
#first ⇒ Object
17 18 19 |
# File 'lib/active_pstore/finder_methods.rb', line 17 def first all.first end |
#last ⇒ Object
21 22 23 |
# File 'lib/active_pstore/finder_methods.rb', line 21 def last all.last end |
#take(limit = nil) ⇒ Object
25 26 27 |
# File 'lib/active_pstore/finder_methods.rb', line 25 def take(limit = nil) limit ? all.take(limit) : first end |