Class: DuckRecord::Associations::Builder::SingularAssociation
- Inherits:
-
Association
- Object
- Association
- DuckRecord::Associations::Builder::SingularAssociation
- Defined in:
- lib/duck_record/associations/builder/singular_association.rb
Overview
:nodoc:
Direct Known Subclasses
Constant Summary
Constants inherited from Association
Class Method Summary collapse
-
.define_accessors(model, reflection) ⇒ Object
:nodoc:.
-
.define_constructors(mixin, name) ⇒ Object
Defines the (build|create)_association methods for belongs_to or has_one association.
Methods inherited from Association
build, create_reflection, define_callbacks, define_extensions, define_readers, define_validations, define_writers, macro, valid_options, validate_options
Class Method Details
.define_accessors(model, reflection) ⇒ Object
:nodoc:
5 6 7 8 9 10 11 |
# File 'lib/duck_record/associations/builder/singular_association.rb', line 5 def self.define_accessors(model, reflection) super mixin = model.generated_association_methods name = reflection.name define_constructors(mixin, name) if reflection.constructable? end |
.define_constructors(mixin, name) ⇒ Object
Defines the (build|create)_association methods for belongs_to or has_one association
14 15 16 17 18 19 20 |
# File 'lib/duck_record/associations/builder/singular_association.rb', line 14 def self.define_constructors(mixin, name) mixin.class_eval " def build_\#{name}(*args, &block)\n association(:\#{name}).build(*args, &block)\n end\n CODE\nend\n", __FILE__, __LINE__ + 1 |