Sha256: 7cfa0f0b3956e21081ebe2af28049cd366c66732024aa024a24549739a2a791c

Contents?: true

Size: 1.14 KB

Versions: 31

Compression:

Stored size: 1.14 KB

Contents

module Spree
  module Backend
    module Callbacks
      extend ActiveSupport::Concern

      module ClassMethods

        attr_accessor :callbacks

        protected

        def new_action
          @callbacks ||= {}
          @callbacks[:new_action] ||= Spree::ActionCallbacks.new
        end

        def create
          @callbacks ||= {}
          @callbacks[:create] ||= Spree::ActionCallbacks.new
        end

        def update
          @callbacks ||= {}
          @callbacks[:update] ||= Spree::ActionCallbacks.new
        end

        def destroy
          @callbacks ||= {}
          @callbacks[:destroy] ||= Spree::ActionCallbacks.new
        end
      end

      protected

      def invoke_callbacks(action, callback_type)
        callbacks = self.class.callbacks || {}
        return if callbacks[action].nil?
        case callback_type.to_sym
          when :before then callbacks[action].before_methods.each {|method| send method }
          when :after  then callbacks[action].after_methods.each  {|method| send method }
          when :fails  then callbacks[action].fails_methods.each  {|method| send method }
        end
      end

    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
spree_backend-2.3.13 lib/spree/backend/callbacks.rb
spree_backend-2.2.14 lib/spree/backend/callbacks.rb
spree_backend-2.3.12 lib/spree/backend/callbacks.rb
spree_backend-2.2.13 lib/spree/backend/callbacks.rb
spree_backend-2.3.11 lib/spree/backend/callbacks.rb
spree_backend-2.2.12 lib/spree/backend/callbacks.rb
spree_backend-2.3.10 lib/spree/backend/callbacks.rb
spree_backend-2.3.9 lib/spree/backend/callbacks.rb
spree_backend-2.2.11 lib/spree/backend/callbacks.rb
spree_backend-2.2.10 lib/spree/backend/callbacks.rb
spree_backend-2.3.8 lib/spree/backend/callbacks.rb
spree_backend-2.3.7 lib/spree/backend/callbacks.rb
spree_backend-2.2.9 lib/spree/backend/callbacks.rb
spree_backend-2.3.6 lib/spree/backend/callbacks.rb
spree_backend-2.2.8 lib/spree/backend/callbacks.rb
spree_backend-2.3.5 lib/spree/backend/callbacks.rb
spree_backend-2.2.7 lib/spree/backend/callbacks.rb
spree_backend-2.4.0.rc3 lib/spree/backend/callbacks.rb
spree_backend-2.4.0.rc2 lib/spree/backend/callbacks.rb
spree_backend-2.4.0.rc1 lib/spree/backend/callbacks.rb