class Rack::ServerPages::Filter
Constants
- TYPES
Public Class Methods
extract_filters_from_helpers(helpers)
click to toggle source
# File lib/rack/server_pages.rb, line 123 def self.extract_filters_from_helpers(helpers) new.tap do |filter| helpers.each do |helper| next unless helper.is_a? Module TYPES.each do |type| if helper.method_defined?(type) filter[type] << helper.instance_method(type) helper.class_eval { undef :"#{type}" } end end end end end
new()
click to toggle source
# File lib/rack/server_pages.rb, line 98 def initialize @filters = Hash[[TYPES, Array.new(TYPES.size) { [] }].transpose] end
Public Instance Methods
[](type)
click to toggle source
# File lib/rack/server_pages.rb, line 102 def [](type) @filters[type] end
add(type, *args, &block)
click to toggle source
# File lib/rack/server_pages.rb, line 114 def add(type, *args, &block) @filters[type] << block if block_given? @filters[type].concat args unless args.empty? end
invoke(scope, type)
click to toggle source
# File lib/rack/server_pages.rb, line 119 def invoke(scope, type) @filters[type].each { |f| f.respond_to?(:bind) ? f.bind(scope).call : scope.instance_exec(&f) } end
merge(other)
click to toggle source
# File lib/rack/server_pages.rb, line 106 def merge(other) TYPES.each { |type| @filters[type].concat other[type] } end
merge_from_helpers(helpers)
click to toggle source
# File lib/rack/server_pages.rb, line 110 def merge_from_helpers(helpers) merge(self.class.extract_filters_from_helpers(helpers)) end