Class: ServiCraft::Update
- Inherits:
-
Object
- Object
- ServiCraft::Update
- Defined in:
- lib/servi_craft/update.rb
Overview
UpdateRecordService
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #call(before_assign_attributes: proc {}, before_update: proc {}, after_successful_update: proc {}, after_failed_update: proc {}, finally: proc {}) ⇒ Object
-
#initialize(record, params) ⇒ Update
constructor
A new instance of Update.
Constructor Details
#initialize(record, params) ⇒ Update
Returns a new instance of Update.
9 10 11 12 13 14 |
# File 'lib/servi_craft/update.rb', line 9 def initialize(record, params) @record = record @model = @record.class @params = params @response = ::EchoCraft::ServiceObjects::Update.new(@record, @params) end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/servi_craft/update.rb', line 7 def model @model end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'lib/servi_craft/update.rb', line 7 def params @params end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
7 8 9 |
# File 'lib/servi_craft/update.rb', line 7 def record @record end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/servi_craft/update.rb', line 7 def response @response end |
Instance Method Details
#call(before_assign_attributes: proc {}, before_update: proc {}, after_successful_update: proc {}, after_failed_update: proc {}, finally: proc {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/servi_craft/update.rb', line 16 def call(before_assign_attributes: proc {}, before_update: proc {}, after_successful_update: proc {}, after_failed_update: proc {}, finally: proc {}) begin before_assign_attributes.call @record.assign_attributes(@params) before_update.call process_record_update(@record.save, after_successful_update: after_successful_update, after_failed_update: after_failed_update) rescue StandardError => e puts "#{e.class}: #{e.message}" puts e.backtrace.join("\n") fail_update(after_failed_update: after_failed_update) end finally.call @response end |