Module: Mince::Model::Finders::ClassMethods
- Defined in:
- lib/mince/model/finders.rb
Instance Method Summary collapse
-
#all ⇒ Object
Returns all models from the data model.
-
#all_before(field, value) ⇒ Object
Returns all models where the field has a value that is less than the given value.
-
#all_by_field(field, value) ⇒ Object
Finds all fields that match the given field value pair.
-
#all_by_fields(hash) ⇒ Object
Finds all fields that match the given hash.
-
#find(id) ⇒ Object
Returns a model that matches a given id, returns nil if none found.
-
#find_by_field(field, value) ⇒ Object
Finds a model for the given field value pair.
-
#find_by_fields(hash) ⇒ Object
Finds a model for the given hash.
-
#find_or_initialize_by(hash) ⇒ Object
Finds or initializes a model for the given hash.
Instance Method Details
#all ⇒ Object
Returns all models from the data model
42 43 44 |
# File 'lib/mince/model/finders.rb', line 42 def all data_model.all.map{|a| new a } end |
#all_before(field, value) ⇒ Object
Returns all models where the field has a value that is less than the given value
53 54 55 |
# File 'lib/mince/model/finders.rb', line 53 def all_before(field, value) data_model.all_before(field, value).map{|a| new(a) } end |
#all_by_field(field, value) ⇒ Object
Finds all fields that match the given field value pair
27 28 29 |
# File 'lib/mince/model/finders.rb', line 27 def all_by_field(field, value) data_model.all_by_field(field, value).map{|a| new(a) } end |
#all_by_fields(hash) ⇒ Object
Finds all fields that match the given hash
32 33 34 |
# File 'lib/mince/model/finders.rb', line 32 def all_by_fields(hash) data_model.all_by_fields(hash).map{|a| new(a) } end |
#find(id) ⇒ Object
Returns a model that matches a given id, returns nil if none found
47 48 49 50 |
# File 'lib/mince/model/finders.rb', line 47 def find(id) a = data_model.find(id) new a if a end |
#find_by_field(field, value) ⇒ Object
Finds a model for the given field value pair
15 16 17 18 |
# File 'lib/mince/model/finders.rb', line 15 def find_by_field(field, value) d = data_model.find_by_field(field, value) new d if d end |
#find_by_fields(hash) ⇒ Object
Finds a model for the given hash
21 22 23 24 |
# File 'lib/mince/model/finders.rb', line 21 def find_by_fields(hash) d = data_model.find_by_fields(hash) new d if d end |
#find_or_initialize_by(hash) ⇒ Object
Finds or initializes a model for the given hash
37 38 39 |
# File 'lib/mince/model/finders.rb', line 37 def find_or_initialize_by(hash) find_by_fields(hash) || new(hash) end |