Sha256: 30f100316670267934bdf1b6748553dc9179ac57d3a5e4e3651039ea8fd48e07

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

require 'active_support/concern'

module Praxis
  module Callbacks
    extend ::ActiveSupport::Concern

    included do
      class_attribute :before_callbacks, :after_callbacks, :around_callbacks
      self.before_callbacks = Hash.new
      self.after_callbacks = Hash.new
      self.around_callbacks = Hash.new
    end
    
    module ClassMethods
 
      def before(*stage_path, **conditions, &block)
        stage_path = [:action] if stage_path.empty?
        before_callbacks[stage_path] ||= Array.new
        before_callbacks[stage_path] << [conditions, block]
      end
      
      def after(*stage_path, **conditions, &block)
        stage_path = [:action] if stage_path.empty?
        after_callbacks[stage_path] ||= Array.new
        after_callbacks[stage_path] << [conditions, block]
      end
      
      def around(*stage_path, **conditions, &block)
        stage_path = [:action] if stage_path.empty?
        around_callbacks[stage_path] ||= Array.new
        around_callbacks[stage_path] << [conditions, block]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
praxis-0.10.1 lib/praxis/callbacks.rb
praxis-0.10.0 lib/praxis/callbacks.rb