Sha256: 30ad0c291e1cf7f148907bc2a3cad81be82adea29340ecc4dc75e62362e1cc30

Contents?: true

Size: 1.13 KB

Versions: 96

Compression:

Stored size: 1.13 KB

Contents

# Simpified version of callbacks
# Does not support if
class Jets::Controller
  module Callbacks
    extend ActiveSupport::Concern
    included do
      class_attribute :before_actions
      self.before_actions = []
      class_attribute :after_actions
      self.after_actions = []

      def self.before_action(meth, options={})
        self.before_actions += [[meth, options]]
      end

      def self.after_action(meth, options={})
        self.after_actions += [[meth, options]]
      end
    end # included

    # Instance Methods
    # define run_before_actions and run_after_actions
    [:before, :after].each do |type|
      define_method "run_#{type}_actions" do
        called_method = @meth.to_sym
        callbacks = self.class.send("#{type}_actions")
        callbacks.each do |array|
          callback, options = array

          except = options[:except]
          next if except && except.include?(called_method)

          only = options[:only]
          if only
            send(callback) if only.include?(called_method)
          else
            send(callback)
          end
        end
      end
    end
  end # ClassOptions
end

Version data entries

96 entries across 96 versions & 1 rubygems

Version Path
jets-0.6.6 lib/jets/controller/callbacks.rb
jets-0.6.5 lib/jets/controller/callbacks.rb
jets-0.6.4 lib/jets/controller/callbacks.rb
jets-0.6.3 lib/jets/controller/callbacks.rb
jets-0.6.2 lib/jets/controller/callbacks.rb
jets-0.6.1 lib/jets/controller/callbacks.rb
jets-0.6.0 lib/jets/controller/callbacks.rb
jets-0.5.8 lib/jets/controller/callbacks.rb
jets-0.5.7 lib/jets/controller/callbacks.rb
jets-0.5.6 lib/jets/controller/callbacks.rb
jets-0.5.5 lib/jets/controller/callbacks.rb
jets-0.5.4 lib/jets/controller/callbacks.rb
jets-0.5.3 lib/jets/controller/callbacks.rb
jets-0.5.2 lib/jets/controller/callbacks.rb
jets-0.5.1 lib/jets/controller/callbacks.rb
jets-0.5.0 lib/jets/controller/callbacks.rb