Class: ActiveData::Model::Associations::Reflections::EmbedsOne
- Defined in:
- lib/active_data/model/associations/reflections/embeds_one.rb
Direct Known Subclasses
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#name, #options, #parent_reflection
Class Method Summary collapse
- .build(target, generated_methods, name, options = {}, &block) ⇒ Object
- .generate_methods(name, target) ⇒ Object
Instance Method Summary collapse
Methods inherited from Base
association_class, #belongs_to?, #build_association, #default, #initialize, #inspect, #klass, #macro, #read_source, #write_source
Constructor Details
This class inherits a constructor from ActiveData::Model::Associations::Reflections::Base
Class Method Details
.build(target, generated_methods, name, options = {}, &block) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/active_data/model/associations/reflections/embeds_one.rb', line 6 def self.build target, generated_methods, name, = {}, &block if target < ActiveData::Model::Attributes target.add_attribute(ActiveData::Model::Attributes::Reflections::Base, name) end [:validate] = true unless .key?(:validate) super end |
.generate_methods(name, target) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/active_data/model/associations/reflections/embeds_one.rb', line 14 def self.generate_methods name, target target.class_eval " def \#{name} force_reload = false\n association(:\#{name}).reader(force_reload)\n end\n\n def \#{name}= value\n association(:\#{name}).writer(value)\n end\n\n def build_\#{name} attributes = {}\n association(:\#{name}).build(attributes)\n end\n\n def create_\#{name} attributes = {}\n association(:\#{name}).create(attributes)\n end\n\n def create_\#{name}! attributes = {}\n association(:\#{name}).create!(attributes)\n end\n RUBY\nend\n", __FILE__, __LINE__ + 1 |