Class: RiderKick::Builders::AbstractActiveRecordEntityBuilder
- Inherits:
-
Object
- Object
- RiderKick::Builders::AbstractActiveRecordEntityBuilder
- Defined in:
- lib/rider_kick/builders/abstract_active_record_entity_builder.rb
Overview
Helps to take an instance of an AR model and wrap it up in the given Entity Any columns from the AR model that do not directly map to an attribute on the Entity can be specified by overriding #attributes_for_entity.
Class Method Summary collapse
- .acts_as_builder_for_entity(entity_class) ⇒ Object
- .belongs_to(relation_name, use:) ⇒ Object
- .has_many(relation_name, use:) ⇒ Object
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(params, *args) ⇒ AbstractActiveRecordEntityBuilder
constructor
A new instance of AbstractActiveRecordEntityBuilder.
Constructor Details
#initialize(params, *args) ⇒ AbstractActiveRecordEntityBuilder
Returns a new instance of AbstractActiveRecordEntityBuilder.
39 40 41 42 |
# File 'lib/rider_kick/builders/abstract_active_record_entity_builder.rb', line 39 def initialize(params, *args) @params = params @args = args end |
Class Method Details
.acts_as_builder_for_entity(entity_class) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rider_kick/builders/abstract_active_record_entity_builder.rb', line 11 def self.acts_as_builder_for_entity(entity_class) @has_many_builders = [] @belongs_to_builders = [] define_singleton_method :has_many_builders do @has_many_builders end define_singleton_method :belongs_to_builders do @belongs_to_builders end define_method :entity_class do entity_class end private :entity_class end |
.belongs_to(relation_name, use:) ⇒ Object
34 35 36 |
# File 'lib/rider_kick/builders/abstract_active_record_entity_builder.rb', line 34 def self.belongs_to(relation_name, use:) @belongs_to_builders << [relation_name, use] end |
.has_many(relation_name, use:) ⇒ Object
30 31 32 |
# File 'lib/rider_kick/builders/abstract_active_record_entity_builder.rb', line 30 def self.has_many(relation_name, use:) @has_many_builders << [relation_name, use] end |
Instance Method Details
#build ⇒ Object
44 45 46 |
# File 'lib/rider_kick/builders/abstract_active_record_entity_builder.rb', line 44 def build entity_class.new(all_attributes_for_entity) end |