Module: BlockScore::Actions::Update

Extended by:
Forwardable
Included in:
Candidate
Defined in:
lib/blockscore/actions/update.rb

Overview

Public: Contains the :save instance method, which updates the object with the BlockScore API to persist the changes.

Examples

class Foo
  include BlockScore::Actions::Update
end

foo = Foo.new
foo.name_first = 'John'
foo.save
# => true

Constant Summary collapse

PERSISTENT_ATTRIBUTES =

Attributes which will not change once the object is created.

[
  :id,
  :object,
  :created_at,
  :updated_at,
  :livemode
]

Instance Method Summary collapse

Instance Method Details

#filter_paramsObject

Filters out the non-updateable params.



40
41
42
43
# File 'lib/blockscore/actions/update.rb', line 40

def filter_params
  # Cannot %i syntax, not introduced until Ruby 2.0.0
  attributes.reject { |key, _| PERSISTENT_ATTRIBUTES.include?(key) }
end

#save!Object



30
31
32
33
34
35
36
37
# File 'lib/blockscore/actions/update.rb', line 30

def save!
  if respond_to? :id
    patch("#{endpoint}/#{id}", filter_params)
    true
  else
    super
  end
end