Class: ActionController::Base

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

Class Method Summary collapse

Class Method Details

.immediate_subclassesObject



38
39
40
# File 'lib/freshy_filter_chain.rb', line 38

def immediate_subclasses
  @immediate_subclasses ||= []
end

.inherited_with_subclass_recording(child) ⇒ Object



42
43
44
45
# File 'lib/freshy_filter_chain.rb', line 42

def inherited_with_subclass_recording(child)
  immediate_subclasses << child
  inherited_without_subclass_recording(child)
end

.record_filter_chain_ops_for(*filter_methods) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/freshy_filter_chain.rb', line 7

def self.record_filter_chain_ops_for(*filter_methods)
  filter_methods.each do |meth|
    class_eval <<-CODE
      def #{meth}_with_recording(*filters, &block)
        filter_operation = lambda { #{meth}_without_recording(*filters, &block) }
        filter_operation.call
        recorded_filter_chain_ops << filter_operation
        refresh_subclass_filter_chains
      end
      alias_method_chain meth, :recording
    CODE
  end
end

.recorded_filter_chain_opsObject



48
49
50
# File 'lib/freshy_filter_chain.rb', line 48

def recorded_filter_chain_ops
  @recorded_filter_chain_ops ||= []
end

.refresh_subclass_filter_chainsObject



26
27
28
29
30
31
32
# File 'lib/freshy_filter_chain.rb', line 26

def refresh_subclass_filter_chains
  immediate_subclasses.each do |child|
    child.write_inheritable_attribute('filter_chain', filter_chain.dup)
    child.replay_filter_chain_ops
    child.refresh_subclass_filter_chains
  end
end

.replay_filter_chain_opsObject



34
35
36
# File 'lib/freshy_filter_chain.rb', line 34

def replay_filter_chain_ops
  recorded_filter_chain_ops.each { |filter_chain_op| filter_chain_op.call }
end