Class: ConcurrentPipeline::Changeset::UpdateDelta

Inherits:
Struct
  • Object
show all
Defined in:
lib/concurrent_pipeline/changeset.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#deltaObject

Returns the value of attribute delta

Returns:

  • (Object)

    the current value of delta



51
52
53
# File 'lib/concurrent_pipeline/changeset.rb', line 51

def delta
  @delta
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



51
52
53
# File 'lib/concurrent_pipeline/changeset.rb', line 51

def id
  @id
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of 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_jsonObject



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