Class: ConcurrentPipeline::Changeset::UpdateDelta
- Inherits:
-
Struct
- Object
- Struct
- ConcurrentPipeline::Changeset::UpdateDelta
- Defined in:
- lib/concurrent_pipeline/changeset.rb
Instance Attribute Summary collapse
-
#delta ⇒ Object
Returns the value of attribute delta.
-
#id ⇒ Object
Returns the value of attribute id.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#delta ⇒ Object
Returns the value of attribute delta
51 52 53 |
# File 'lib/concurrent_pipeline/changeset.rb', line 51 def delta @delta end |
#id ⇒ Object
Returns the value of attribute id
51 52 53 |
# File 'lib/concurrent_pipeline/changeset.rb', line 51 def id @id end |
#type ⇒ Object
Returns the value of attribute type
51 52 53 |
# File 'lib/concurrent_pipeline/changeset.rb', line 51 def type @type end |
Class Method Details
.from_json(json) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/concurrent_pipeline/changeset.rb', line 66 def self.from_json(json) new( id: json.fetch(:id), type: json.fetch(:type), delta: json.fetch(:delta), ) end |
Instance Method Details
#apply(store) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/concurrent_pipeline/changeset.rb', line 52 def apply(store) current_model = store.find(type, id) # Todo: detect if changed underfoot Result.new( store.update( id: id, type: type, attributes: current_model.attributes.merge(delta) ) ) end |
#as_json ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/concurrent_pipeline/changeset.rb', line 74 def as_json { action: :update, id: id, type: type, delta: delta } end |