Sha256: 47433aa54cd91a3c80c50fb354de159fce810fd77130ae3e54bc674b872b08a4

Contents?: true

Size: 984 Bytes

Versions: 12

Compression:

Stored size: 984 Bytes

Contents

module ApiResource
  
  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

12 entries across 12 versions & 2 rubygems

Version Path
api_resource-0.2.11 lib/api_resource/callbacks.rb
api_resource-0.2.10 lib/api_resource/callbacks.rb
api_resource-0.2.9 lib/api_resource/callbacks.rb
api_resource-0.2.8 lib/api_resource/callbacks.rb
api_resource-0.2.7 lib/api_resource/callbacks.rb
api_resource-0.2.6 lib/api_resource/callbacks.rb
api_resource-0.2.5 lib/api_resource/callbacks.rb
api_resource-0.2.4 lib/api_resource/callbacks.rb
api_resource-0.2.3 lib/api_resource/callbacks.rb
api_resource-0.2.2 lib/api_resource/callbacks.rb
api_resource-0.2.1 lib/api_resource/callbacks.rb
resource-0.1.0 lib/api_resource/callbacks.rb