Module: AbstractModel
- Included in:
- EmbeddedAssociation, MongoModel
- Defined in:
- lib/yodel/models/core/model/abstract_model.rb
Instance Method Summary collapse
- #embed_many(name, options = {}, &block) ⇒ Object (also: #add_embed_many)
- #embed_one(name, options = {}, &block) ⇒ Object (also: #add_embed_one)
- #field(name, type, options = {}) ⇒ Object (also: #add_field)
- #fields ⇒ Object
- #many(name, options = {}) ⇒ Object (also: #add_many)
- #modify_field(name, options = {}) ⇒ Object
- #one(name, options = {}) ⇒ Object (also: #add_one)
- #remove_field(name) ⇒ Object
Instance Method Details
#embed_many(name, options = {}, &block) ⇒ Object Also known as: add_embed_many
24 25 26 27 |
# File 'lib/yodel/models/core/model/abstract_model.rb', line 24 def (name, ={}, &block) = field(name, 'many_embedded', ) .instance_exec(, &block) if block_given? end |
#embed_one(name, options = {}, &block) ⇒ Object Also known as: add_embed_one
30 31 32 33 |
# File 'lib/yodel/models/core/model/abstract_model.rb', line 30 def (name, ={}, &block) = field(name, 'one_embedded', ) .instance_exec(, &block) if block_given? end |
#field(name, type, options = {}) ⇒ Object Also known as: add_field
6 7 8 9 10 |
# File 'lib/yodel/models/core/model/abstract_model.rb', line 6 def field(name, type, ={}) type = type.to_s = deep_stringify_keys({'type' => type}.merge()) fields[name.to_s] = Field.field_from_type(type).new(name.to_s, ) end |
#fields ⇒ Object
2 3 4 |
# File 'lib/yodel/models/core/model/abstract_model.rb', line 2 def fields @fields ||= {} end |
#many(name, options = {}) ⇒ Object Also known as: add_many
36 37 38 39 |
# File 'lib/yodel/models/core/model/abstract_model.rb', line 36 def many(name, ={}) type = query_association?() ? 'many_query' : 'many_store' field(name, type, ) end |
#modify_field(name, options = {}) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/yodel/models/core/model/abstract_model.rb', line 13 def modify_field(name, ={}) field = fields[name.to_s] field. = field..dup.merge(deep_stringify_keys()) field.instance_exec(field, &block) if block_given? changed!('record_fields') if respond_to?(:changed!) end |
#one(name, options = {}) ⇒ Object Also known as: add_one
42 43 44 45 |
# File 'lib/yodel/models/core/model/abstract_model.rb', line 42 def one(name, ={}) type = query_association?() ? 'one_query' : 'one_store' field(name, type, ) end |
#remove_field(name) ⇒ Object
20 21 22 |
# File 'lib/yodel/models/core/model/abstract_model.rb', line 20 def remove_field(name) fields.delete(name.to_s) end |