Sha256: c6e815e03914d22a4e5ac02442bda2b956b70e106aa1ac3d0a4b8ba99fb53f3f

Contents?: true

Size: 1.06 KB

Versions: 20

Compression:

Stored size: 1.06 KB

Contents

module Spree
  module Backend
    module Callbacks
      extend ActiveSupport::Concern

      module ClassMethods
        attr_accessor :callbacks

        protected

        def new_action
          custom_callback(:new_action)
        end

        def create
          custom_callback(:create)
        end

        def update
          custom_callback(:update)
        end

        def destroy
          custom_callback(:destroy)
        end

        def custom_callback(action)
          @callbacks ||= {}
          @callbacks[action] ||= 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

20 entries across 20 versions & 1 rubygems

Version Path
spree_backend-3.4.6 lib/spree/backend/callbacks.rb
spree_backend-3.6.6 lib/spree/backend/callbacks.rb
spree_backend-3.6.5 lib/spree/backend/callbacks.rb
spree_backend-3.6.4 lib/spree/backend/callbacks.rb
spree_backend-3.6.3 lib/spree/backend/callbacks.rb
spree_backend-3.6.2 lib/spree/backend/callbacks.rb
spree_backend-3.6.1 lib/spree/backend/callbacks.rb
spree_backend-3.6.0 lib/spree/backend/callbacks.rb
spree_backend-3.5.0 lib/spree/backend/callbacks.rb
spree_backend-3.6.0.rc1 lib/spree/backend/callbacks.rb
spree_backend-3.5.0.rc2 lib/spree/backend/callbacks.rb
spree_backend-3.5.0.rc1 lib/spree/backend/callbacks.rb
spree_backend-3.4.5 lib/spree/backend/callbacks.rb
spree_backend-3.4.4 lib/spree/backend/callbacks.rb
spree_backend-3.4.3 lib/spree/backend/callbacks.rb
spree_backend-3.4.2 lib/spree/backend/callbacks.rb
spree_backend-3.4.1 lib/spree/backend/callbacks.rb
spree_backend-3.4.0 lib/spree/backend/callbacks.rb
spree_backend-3.4.0.rc2 lib/spree/backend/callbacks.rb
spree_backend-3.4.0.rc1 lib/spree/backend/callbacks.rb