Class: PlainModel::AssociationBuilder
- Inherits:
-
Object
- Object
- PlainModel::AssociationBuilder
- Defined in:
- lib/plain_model/association_builder.rb
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(model_class, options = {}) ⇒ AssociationBuilder
constructor
A new instance of AssociationBuilder.
- #load_records(name, records, context: nil, includes: []) ⇒ Object
Constructor Details
#initialize(model_class, options = {}) ⇒ AssociationBuilder
Returns a new instance of AssociationBuilder.
7 8 9 10 |
# File 'lib/plain_model/association_builder.rb', line 7 def initialize(model_class, = {}) @model_class = model_class = end |
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
5 6 7 |
# File 'lib/plain_model/association_builder.rb', line 5 def model_class @model_class end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/plain_model/association_builder.rb', line 5 def end |
Instance Method Details
#load_records(name, records, context: nil, includes: []) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/plain_model/association_builder.rb', line 12 def load_records(name, records, context: nil, includes: []) apply = .fetch(:apply) { :"_records_for_#{name}" } args = [records, context: context, includes: includes, association: name] if apply.is_a?(Symbol) model_class.public_send(apply, *args) else model_class.instance_exec(*args, &apply) end end |