Sha256: bbeb6d8849ce77565e4406e002acd2cc9b62d4ee69d2ee47c8343279150ec96f

Contents?: true

Size: 1.3 KB

Versions: 131

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

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

        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

131 entries across 131 versions & 2 rubygems

Version Path
solidus_backend-3.2.5 lib/spree/backend/callbacks.rb
solidus_backend-3.2.4 lib/spree/backend/callbacks.rb
solidus_backend-3.2.3 lib/spree/backend/callbacks.rb
solidus_backend-3.1.8 lib/spree/backend/callbacks.rb
solidus_backend-3.0.8 lib/spree/backend/callbacks.rb
solidus_backend-3.2.2 lib/spree/backend/callbacks.rb
solidus_backend-3.2.1 lib/spree/backend/callbacks.rb
solidus_backend-3.2.0 lib/spree/backend/callbacks.rb
solidus_backend-3.2.0.alpha lib/spree/backend/callbacks.rb
solidus_backend-3.0.7 lib/spree/backend/callbacks.rb
solidus_backend-2.11.17 lib/spree/backend/callbacks.rb
solidus_backend-3.1.7 lib/spree/backend/callbacks.rb
solidus_backend-2.11.16 lib/spree/backend/callbacks.rb
solidus_backend-3.0.6 lib/spree/backend/callbacks.rb
solidus_backend-3.1.6 lib/spree/backend/callbacks.rb
solidus_backend-2.11.15 lib/spree/backend/callbacks.rb
solidus_backend-2.11.14 lib/spree/backend/callbacks.rb
solidus_backend-3.0.5 lib/spree/backend/callbacks.rb
solidus_backend-3.1.5 lib/spree/backend/callbacks.rb
solidus_backend-2.11.13 lib/spree/backend/callbacks.rb