Sha256: fcf9f22127653d00067355fae692c9e0a28d9f7b860ba8e225161ba177bc13ba

Contents?: true

Size: 988 Bytes

Versions: 1

Compression:

Stored size: 988 Bytes

Contents

module OldApiResource
  
  module Callbacks
    
    extend ActiveSupport::Concern
    
    included do
      
      extend ActiveModel::Callbacks
      
      define_model_callbacks :save, :create, :update, :destroy
      
      [:save, :create, :update, :destroy].each do |action|
        alias_method_chain action, :callbacks
      end
      
    end
    
    module InstanceMethods
      
      def save_with_callbacks(*args)
        _run_save_callbacks do
          save_without_callbacks(*args)
        end
      end
      
      def create_with_callbacks(*args)
        _run_create_callbacks do
          create_without_callbacks(*args)
        end
      end
      
      def update_with_callbacks(*args)
        _run_update_callbacks do
          update_without_callbacks(*args)
        end
      end
      
      def destroy_with_callbacks(*args)
        _run_destroy_callbacks do
          destroy_without_callbacks(*args)
        end
      end
      
    end
    
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
old_api_resource-0.3.0 lib/old_api_resource/callbacks.rb