Sha256: 981b1f53c8a0ad9ee3ee27290f35816049b0e9ecdd5539106d18305c67612c61

Contents?: true

Size: 1002 Bytes

Versions: 23

Compression:

Stored size: 1002 Bytes

Contents

# frozen_string_literal: true

module Praxis
  module Callbacks
    extend ::ActiveSupport::Concern

    included do
      class_attribute :before_callbacks, :after_callbacks, :around_callbacks
      self.before_callbacks = ({})
      self.after_callbacks = ({})
      self.around_callbacks = ({})
    end

    module ClassMethods
      def before(*stage_path, **conditions, &block)
        stage_path = [:action] if stage_path.empty?
        before_callbacks[stage_path] ||= []
        before_callbacks[stage_path] << [conditions, block]
      end

      def after(*stage_path, **conditions, &block)
        stage_path = [:action] if stage_path.empty?
        after_callbacks[stage_path] ||= []
        after_callbacks[stage_path] << [conditions, block]
      end

      def around(*stage_path, **conditions, &block)
        stage_path = [:action] if stage_path.empty?
        around_callbacks[stage_path] ||= []
        around_callbacks[stage_path] << [conditions, block]
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
praxis-2.0.0 lib/praxis/callbacks.rb
praxis-2.0.pre.40 lib/praxis/callbacks.rb
praxis-2.0.pre.39 lib/praxis/callbacks.rb
praxis-2.0.pre.38 lib/praxis/callbacks.rb
praxis-2.0.pre.37 lib/praxis/callbacks.rb
praxis-2.0.pre.36 lib/praxis/callbacks.rb
praxis-2.0.pre.35 lib/praxis/callbacks.rb
praxis-2.0.pre.34 lib/praxis/callbacks.rb
praxis-2.0.pre.33 lib/praxis/callbacks.rb
praxis-2.0.pre.32 lib/praxis/callbacks.rb
praxis-2.0.pre.31 lib/praxis/callbacks.rb
praxis-2.0.pre.30 lib/praxis/callbacks.rb
praxis-2.0.pre.29 lib/praxis/callbacks.rb
praxis-2.0.pre.28 lib/praxis/callbacks.rb
praxis-2.0.pre.27 lib/praxis/callbacks.rb
praxis-2.0.pre.26 lib/praxis/callbacks.rb
praxis-2.0.pre.25 lib/praxis/callbacks.rb
praxis-2.0.pre.24 lib/praxis/callbacks.rb
praxis-2.0.pre.23 lib/praxis/callbacks.rb
praxis-2.0.pre.22 lib/praxis/callbacks.rb