Class: ActionTracer::Filters

Inherits:
Object
  • Object
show all
Defined in:
lib/action_tracer/filters.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(before = [], after = [], around = [], action:) ⇒ Filters

Returns a new instance of Filters.



47
48
49
50
51
52
# File 'lib/action_tracer/filters.rb', line 47

def initialize(before = [], after = [], around = [], action:)
  @before = before
  @after = after
  @around = around
  @action = action
end

Class Method Details

.build(controller) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/action_tracer/filters.rb', line 55

def build(controller)
  filters = { before: [], after: [], around: [] }
  raw_filters = controller.__callbacks[:process_action].send(:chain).group_by(&:kind)
  raw_filters.each do |kind, filter|
    filters[kind] = filter.map { |f| f.__send__(filter_method) }.map do |f|
      Filter.new(f, method: f.is_a?(Symbol) ? controller.method(f) : f)
    end
  end
  new(filters[:before], filters[:after], filters[:around], action: Action.build(controller))
end

Instance Method Details



73
74
75
76
77
# File 'lib/action_tracer/filters.rb', line 73

def print
  invoked_before.map(&:to_a).each { |filter| ActionTracer.logger.info filter }
  ActionTracer.logger.info @action.to_a
  invoked_after.map(&:to_a).reverse_each { |filter| ActionTracer.logger.info filter }
end