Class: NiftyServices::BaseDeleteService

Inherits:
BaseCrudService show all
Defined in:
lib/nifty_services/base_delete_service.rb

Constant Summary

Constants inherited from BaseService

NiftyServices::BaseService::CALLBACKS

Instance Attribute Summary

Attributes inherited from BaseCrudService

#record

Attributes inherited from BaseService

#errors, #logger, #options, #response_status, #response_status_code

Instance Method Summary collapse

Methods inherited from BaseCrudService

#changed?, #changed_attributes, get_whitelist_attributes, #initialize, #record_allowed_attributes, #record_attributes_hash, #record_attributes_whitelist, #record_type, record_type, whitelist_attributes

Methods inherited from BaseService

#add_error, #callback_fired?, concern, #default_logger, define_error_response_method, #executed?, #fail?, #initialize, #option_disabled?, #option_enabled?, #option_exists?, #register_callback, register_callback, register_callback_action, #register_callback_action, register_error_response_method, #success?, #valid?

Constructor Details

This class inherits a constructor from NiftyServices::BaseCrudService

Instance Method Details

#executeObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/nifty_services/base_delete_service.rb', line 4

def execute
  execute_action do
    with_before_and_after_callbacks(:delete) do
      if can_execute_action?
        deleted_record = with_before_and_after_callbacks(:delete_record) { delete_record }

        if deleted_record
          success_response
        else
          unprocessable_entity_error!(@record.errors)
        end
      end
    end
  end
end