Class: ApiMaker::UpdateCommand

Inherits:
BaseCommand show all
Defined in:
app/services/api_maker/update_command.rb

Instance Attribute Summary collapse

Attributes inherited from BaseCommand

#api_maker_args, #collection, #collection_instance, #command, #command_response, #commands, #controller, #current_ability

Instance Method Summary collapse

Methods inherited from BaseCommand

command_error_message, each_command, execute_in_thread!, #execute_service_or_fail, #execute_with_response, #fail!, #fail_command_from_service_error_response, #failure_response, #failure_save_response, goldiloader?, #initialize, #inspect, #model_class, run_command, #save_models_or_fail, #serialize_service_errors, #succeed!

Constructor Details

This class inherits a constructor from ApiMaker::BaseCommand

Instance Attribute Details

#serializerObject (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
# File 'app/services/api_maker/update_command.rb', line 4

def execute!
  ApiMaker::Configuration.profile(-> { "UpdateCommand: #{model_class.name}" }) do
    @serializer = serialized_resource(model)
    sanitized_parameters = sanitize_parameters

    if command.model.update(sanitized_parameters)
      success_response
    else
      failure_save_response(model: model, params: sanitized_parameters)
    end
  end
end

#sanitize_parametersObject



17
18
19
# File 'app/services/api_maker/update_command.rb', line 17

def sanitize_parameters
  serializer.resource_instance.permitted_params(ApiMaker::PermittedParamsArgument.new(command: self, model: model))
end

#success_responseObject



21
22
23
24
25
26
# File 'app/services/api_maker/update_command.rb', line 21

def success_response
  succeed!(
    model: serialized_model(model),
    success: true
  )
end