Module: Rango::FiltersMixin

Included in:
StackController
Defined in:
lib/rango/mixins/filters.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(controller) ⇒ Object



5
6
7
# File 'lib/rango/mixins/filters.rb', line 5

def self.included(controller)
  controller.extend(ClassMethods)
end

Instance Method Details

#invoke_action(action) ⇒ Object

for Rango::Controller



10
11
12
13
14
# File 'lib/rango/mixins/filters.rb', line 10

def invoke_action(action)
  self.run_filters(:before, action)
  super(action)
  self.run_filters(:after, action)
end

#run_filters(name, action) ⇒ Object

Since:

  • 0.0.2



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rango/mixins/filters.rb', line 17

def run_filters(name, action)
  # Rango.logger.debug(self.class.instance_variables)
  # Rango.logger.inspect(name: name, action: action)
  self.class.get_filters(name).each do |filter_method, options|
    unless options[:except] && options[:except].include?(action)
      if filter_method.is_a?(Symbol) && self.respond_to?(filter_method)
        Rango.logger.info("Calling filter #{filter_method} for controller #{self}")
        self.send(filter_method)
      elsif filter_method.respond_to?(:call)
        Rango.logger.info("Calling filter #{filter_method.inspect} for controller #{self}")
        self.instance_eval(&filter_method)
      else
        Rango.logger.error("Filter #{filter_method} doesn't exists!")
      end
    end
  end
end