Class: Model::HasMany::Association
- Inherits:
-
Object
- Object
- Model::HasMany::Association
- Defined in:
- app/models/concerns/model/has_many.rb
Instance Attribute Summary collapse
-
#assoc ⇒ Object
readonly
Returns the value of attribute assoc.
-
#singular_name ⇒ Object
readonly
Returns the value of attribute singular_name.
-
#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 29 30 31 32 33 34 35 36 37 |
# File 'app/models/concerns/model/has_many.rb', line 8 def initialize(target, assoc, = {}) @target = target @assoc = assoc.to_sym @singular_name = assoc.to_s.singularize raise 'assoc must be plural' if singular_name == assoc.to_s class_name = [:class_name] || singular_name.to_s.camelize klass = class_name.constantize var_name = "@#{assoc}".to_sym builder_method_name = "build_#{singular_name}".to_sym selector_method_name = "#{assoc}_with".to_sym finder_method_name = "find_#{singular_name}_with".to_sym validate_method_name = "validate_associated_#{assoc}".to_sym define_reader var_name define_attributes_writer var_name, builder_method_name define_builder builder_method_name, klass, assoc define_selector selector_method_name, assoc define_finder finder_method_name, selector_method_name define_find_or_build_method finder_method_name, builder_method_name define_present_method assoc define_empty_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_many.rb', line 6 def assoc @assoc end |
#singular_name ⇒ Object (readonly)
Returns the value of attribute singular_name.
6 7 8 |
# File 'app/models/concerns/model/has_many.rb', line 6 def singular_name @singular_name end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
6 7 8 |
# File 'app/models/concerns/model/has_many.rb', line 6 def target @target end |