Module: Troo::ModelHelpers::ClassMethods
- Defined in:
- lib/troo/helpers/model_helpers.rb
Instance Method Summary collapse
- #by_external_id(id) ⇒ Ohm::Model
- #count(criteria = {}) ⇒ Integer
- #default ⇒ Ohm::Model
- #default? ⇒ TrueClass, FalseClass
- #first(criteria = {}) ⇒ Ohm::Model
- #retrieve(id = nil, options = {}) ⇒ Ohm::Model
- #update(criteria = {}) ⇒ TrueClass
Instance Method Details
#by_external_id(id) ⇒ Ohm::Model
38 39 40 |
# File 'lib/troo/helpers/model_helpers.rb', line 38 def by_external_id(id) first(external_id: id) end |
#count(criteria = {}) ⇒ Integer
31 32 33 34 |
# File 'lib/troo/helpers/model_helpers.rb', line 31 def count(criteria = {}) return all.count if criteria.empty? find(criteria).size end |
#default ⇒ Ohm::Model
20 21 22 |
# File 'lib/troo/helpers/model_helpers.rb', line 20 def default first(default: true) end |
#default? ⇒ TrueClass, FalseClass
25 26 27 |
# File 'lib/troo/helpers/model_helpers.rb', line 25 def default? !!(default) end |
#first(criteria = {}) ⇒ Ohm::Model
6 7 8 9 |
# File 'lib/troo/helpers/model_helpers.rb', line 6 def first(criteria = {}) return all.first if criteria.nil? || criteria.empty? find(criteria).first end |
#retrieve(id = nil, options = {}) ⇒ Ohm::Model
45 46 47 |
# File 'lib/troo/helpers/model_helpers.rb', line 45 def retrieve(id = nil, = {}) Troo::Retrieval::Local.retrieve(self, id, ) end |
#update(criteria = {}) ⇒ TrueClass
13 14 15 16 17 |
# File 'lib/troo/helpers/model_helpers.rb', line 13 def update(criteria = {}) return false if criteria.nil? || criteria.empty? all.map { |record| record.update(criteria) } true end |