Class: ApiMaker::UpdateCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- ApiMaker::UpdateCommand
- Defined in:
- app/services/api_maker/update_command.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
Attributes inherited from BaseCommand
#api_maker_args, #collection, #command_response, #commands, #controller, #current_ability
Instance Method Summary collapse
- #execute! ⇒ Object
- #failure_response ⇒ Object
- #sanitize_parameters ⇒ Object
- #serialized_resource(model) ⇒ Object
- #success_response ⇒ Object
Methods inherited from BaseCommand
#each_command, execute_in_thread!, goldiloader?, #initialize
Constructor Details
This class inherits a constructor from ApiMaker::BaseCommand
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
2 3 4 |
# File 'app/services/api_maker/update_command.rb', line 2 def command @command end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
2 3 4 |
# File 'app/services/api_maker/update_command.rb', line 2 def model @model end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
2 3 4 |
# File 'app/services/api_maker/update_command.rb', line 2 def params @params end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
2 3 4 |
# File 'app/services/api_maker/update_command.rb', line 2 def serializer @serializer end |
Instance Method Details
#execute! ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/services/api_maker/update_command.rb', line 4 def execute! each_command do |command| @command = command @model = command.model @params = command.args || {} @serializer = serialized_resource(model) if command.model.update(sanitize_parameters) success_response else failure_response end end ServicePattern::Response.new(success: true) end |
#failure_response ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/services/api_maker/update_command.rb', line 21 def failure_response command.fail( model: serializer.result, success: false, errors: model.errors. ) end |
#sanitize_parameters ⇒ Object
29 30 31 |
# File 'app/services/api_maker/update_command.rb', line 29 def sanitize_parameters serializer.resource_instance.permitted_params(ApiMaker::PermittedParamsArgument.new(command: command, model: model)) end |
#serialized_resource(model) ⇒ Object
33 34 35 |
# File 'app/services/api_maker/update_command.rb', line 33 def serialized_resource(model) ApiMaker::Serializer.new(ability: current_ability, args: api_maker_args, model: model) end |
#success_response ⇒ Object
37 38 39 40 41 42 |
# File 'app/services/api_maker/update_command.rb', line 37 def success_response command.result( model: serializer.result, success: true ) end |