Class: Model::HasOne::Association
- Inherits:
-
Object
- Object
- Model::HasOne::Association
- Defined in:
- app/models/concerns/model/has_one.rb
Instance Attribute Summary collapse
-
#assoc ⇒ Object
readonly
Returns the value of attribute assoc.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(target, assoc, options = {}) ⇒ Association
constructor
A new instance of Association.
Constructor Details
#initialize(target, assoc, options = {}) ⇒ Association
Returns a new instance of Association.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/concerns/model/has_one.rb', line 8 def initialize(target, assoc, = {}) @target = target @assoc = assoc.to_sym class_name = [:class_name] || assoc.to_s.camelize klass = class_name.constantize builder_method_name = "build_#{assoc}".to_sym validate_method_name = "validate_associated_#{assoc}".to_sym target.send :attr_accessor, assoc define_builder builder_method_name, assoc, klass define_attributes_writer builder_method_name define_present_method assoc define_nil_method assoc define_validate_method validate_method_name, assoc if = [:validate] target.validate validate_method_name, .is_a?(Hash) ? : {} end end |
Instance Attribute Details
#assoc ⇒ Object (readonly)
Returns the value of attribute assoc.
6 7 8 |
# File 'app/models/concerns/model/has_one.rb', line 6 def assoc @assoc end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
6 7 8 |
# File 'app/models/concerns/model/has_one.rb', line 6 def target @target end |