Class: ApiMaker::DestroyCommand

Inherits:
BaseCommand show all
Defined in:
app/services/api_maker/destroy_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_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/destroy_command.rb', line 2

def serializer
  @serializer
end

Instance Method Details

#errors_for_modelObject



14
15
16
17
# File 'app/services/api_maker/destroy_command.rb', line 14

def errors_for_model
  ActiveRecordBetterDependentErrorMessages::DestroyValidator.(model: model) if model.errors.full_messages.empty?
  model.errors.full_messages
end

#execute!Object



4
5
6
7
8
9
10
11
12
# File 'app/services/api_maker/destroy_command.rb', line 4

def execute!
  @serializer = serialized_resource(model)

  if command.model.destroy
    success_response
  else
    failure_response
  end
end

#failure_responseObject



19
20
21
22
23
24
25
# File 'app/services/api_maker/destroy_command.rb', line 19

def failure_response
  fail!(
    model: serialized_model(model),
    success: false,
    errors: errors_for_model
  )
end

#success_responseObject



27
28
29
30
31
32
# File 'app/services/api_maker/destroy_command.rb', line 27

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