Class: ServiCraft::Create
- Inherits:
-
Object
- Object
- ServiCraft::Create
- Defined in:
- lib/servi_craft/create.rb
Overview
CreateRecordService
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_create: proc {}, after_successful_create: proc {}, after_failed_create: proc {}, finally: proc {}) ⇒ Object
-
#initialize(model, params) ⇒ Create
constructor
A new instance of Create.
Constructor Details
#initialize(model, params) ⇒ Create
Returns a new instance of Create.
10 11 12 13 14 |
# File 'lib/servi_craft/create.rb', line 10 def initialize(model, params) @model = model @params = params @response = ::EchoCraft::ServiceObjects::Create.new(@params) end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/servi_craft/create.rb', line 8 def model @model end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/servi_craft/create.rb', line 8 def params @params end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
8 9 10 |
# File 'lib/servi_craft/create.rb', line 8 def record @record end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/servi_craft/create.rb', line 8 def response @response end |
Instance Method Details
#call(before_assign_attributes: proc {}, before_create: proc {}, after_successful_create: proc {}, after_failed_create: proc {}, finally: proc {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/servi_craft/create.rb', line 16 def call(before_assign_attributes: proc {}, before_create: proc {}, after_successful_create: proc {}, after_failed_create: proc {}, finally: proc {}) begin before_assign_attributes.call @record = @model.new(@params) before_create.call process_record_create(@record.save, after_successful_create: after_successful_create, after_failed_create: after_failed_create) rescue StandardError => e puts "#{e.class}: #{e.}" puts e.backtrace.join("\n") fail_create(after_failed_create: after_failed_create) end finally.call @response end |