Class: NiftyServices::BaseUpdateService

Inherits:
BaseCrudService show all
Defined in:
lib/nifty_services/base_update_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?, 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

#changed_attributesObject



23
24
25
26
# File 'lib/nifty_services/base_update_service.rb', line 23

def changed_attributes
  return [] if fail?
  @changed_attributes ||= changes(@last_record, @record, changed_attributes_array)
end

#executeObject



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

def execute
  execute_action do
    with_before_and_after_callbacks(:update) do
      if can_execute_action?
        duplicate_records_before_update

        @record = with_before_and_after_callbacks(:update_record) { update_record }

        if success_updated?
          success_response
        else
          errors = update_errors
          unprocessable_entity_error!(errors) unless errors.empty?
        end
      end
    end
  end
end