Class: VersionedRecord::AttributeBuilder
- Inherits:
-
Object
- Object
- VersionedRecord::AttributeBuilder
- Defined in:
- lib/versioned_record/attribute_builder.rb
Overview
Builds a set of attributes for a new version of a record
Instance Method Summary collapse
-
#attributes(new_attrs) ⇒ Object
Get new attributes hash for the new version Attributes missing in new_attrs will be filled in from the previous version (specified in the constructor).
-
#initialize(record) ⇒ AttributeBuilder
constructor
New Builder.
-
#original_attributes ⇒ Object
The relevant attributes of the previous version i.e: the record we initialized this builder with.
Constructor Details
#initialize(record) ⇒ AttributeBuilder
New Builder
7 8 9 |
# File 'lib/versioned_record/attribute_builder.rb', line 7 def initialize(record) @record = record end |
Instance Method Details
#attributes(new_attrs) ⇒ Object
Get new attributes hash for the new version Attributes missing in new_attrs will be filled in from the previous version (specified in the constructor)
16 17 18 19 20 21 22 23 |
# File 'lib/versioned_record/attribute_builder.rb', line 16 def attributes(new_attrs) @new_attrs = new_attrs.symbolize_keys attrs = original_attributes.merge(@new_attrs.merge({ is_current_version: true, id: @record.id, version: @record.version + 1 })) end |
#original_attributes ⇒ Object
The relevant attributes of the previous version i.e: the record we initialized this builder with
30 31 32 33 34 |
# File 'lib/versioned_record/attribute_builder.rb', line 30 def original_attributes @record.attributes.symbolize_keys.select do |(attr, _)| !%i(created_at updated_at).include?(attr) end end |