Class: DbFuel::Modeling::AttributeRendererSet
- Inherits:
-
Object
- Object
- DbFuel::Modeling::AttributeRendererSet
- Defined in:
- lib/db_fuel/modeling/attribute_renderer_set.rb
Overview
Creates attribute renderers based on attributes passed. Also constains methods to transform attribute renderers and include timestamp attributes if needed.
Constant Summary collapse
- NOW_TYPE =
:nodoc:
'r/value/now'- CREATED_AT =
:created_at- UPDATED_AT =
:updated_at
Instance Attribute Summary collapse
-
#attribute_renderers ⇒ Object
readonly
Returns the value of attribute attribute_renderers.
-
#resolver ⇒ Object
readonly
Returns the value of attribute resolver.
Instance Method Summary collapse
- #created_at_timestamp_attribute ⇒ Object
-
#initialize(resolver:, attributes: []) ⇒ AttributeRendererSet
constructor
A new instance of AttributeRendererSet.
- #make_renderers(attributes) ⇒ Object
- #timestamp_attribute(key) ⇒ Object
-
#timestamp_created_attribute_renderers ⇒ Object
Adds the attributes for created_at and updated_at to the currrent attribute renderers.
-
#timestamp_updated_attribute_renderers ⇒ Object
Adds the attribute for updated_at to the currrent attribute renderers.
- #transform(attribute_renderers, row, time) ⇒ Object
- #updated_at_timestamp_attribute ⇒ Object
Constructor Details
#initialize(resolver:, attributes: []) ⇒ AttributeRendererSet
Returns a new instance of AttributeRendererSet.
22 23 24 25 26 27 28 29 |
# File 'lib/db_fuel/modeling/attribute_renderer_set.rb', line 22 def initialize(resolver:, attributes: []) raise ArgumentError, 'resolver is required' unless resolver @resolver = resolver @attribute_renderers = make_renderers(attributes) freeze end |
Instance Attribute Details
#attribute_renderers ⇒ Object (readonly)
Returns the value of attribute attribute_renderers.
20 21 22 |
# File 'lib/db_fuel/modeling/attribute_renderer_set.rb', line 20 def attribute_renderers @attribute_renderers end |
#resolver ⇒ Object (readonly)
Returns the value of attribute resolver.
20 21 22 |
# File 'lib/db_fuel/modeling/attribute_renderer_set.rb', line 20 def resolver @resolver end |
Instance Method Details
#created_at_timestamp_attribute ⇒ Object
63 64 65 |
# File 'lib/db_fuel/modeling/attribute_renderer_set.rb', line 63 def (CREATED_AT) end |
#make_renderers(attributes) ⇒ Object
49 50 51 52 53 |
# File 'lib/db_fuel/modeling/attribute_renderer_set.rb', line 49 def make_renderers(attributes) Burner::Modeling::Attribute .array(attributes) .map { |a| Burner::Modeling::AttributeRenderer.new(a, resolver) } end |
#timestamp_attribute(key) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/db_fuel/modeling/attribute_renderer_set.rb', line 71 def (key) Burner::Modeling::Attribute.make( key: key, transformers: [ { type: NOW_TYPE } ] ) end |
#timestamp_created_attribute_renderers ⇒ Object
Adds the attributes for created_at and updated_at to the currrent attribute renderers.
32 33 34 35 36 37 38 |
# File 'lib/db_fuel/modeling/attribute_renderer_set.rb', line 32 def = [, ] .map do |a| Burner::Modeling::AttributeRenderer.new(a, resolver) end + attribute_renderers end |
#timestamp_updated_attribute_renderers ⇒ Object
Adds the attribute for updated_at to the currrent attribute renderers.
41 42 43 44 45 46 47 |
# File 'lib/db_fuel/modeling/attribute_renderer_set.rb', line 41 def = [] .map do |a| Burner::Modeling::AttributeRenderer.new(a, resolver) end + attribute_renderers end |
#transform(attribute_renderers, row, time) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/db_fuel/modeling/attribute_renderer_set.rb', line 55 def transform(attribute_renderers, row, time) attribute_renderers.each_with_object({}) do |attribute_renderer, memo| value = attribute_renderer.transform(row, time) resolver.set(memo, attribute_renderer.key, value) end end |
#updated_at_timestamp_attribute ⇒ Object
67 68 69 |
# File 'lib/db_fuel/modeling/attribute_renderer_set.rb', line 67 def (UPDATED_AT) end |