class Tennpipes::Filter
Attributes
block[R]
Public Class Methods
new(mode, scoped_controller, options, args, &block)
click to toggle source
# File lib/tennpipes-base/filter.rb, line 5 def initialize(mode, scoped_controller, options, args, &block) @mode = mode @scoped_controller = scoped_controller @options = options @args = args @block = block end
Public Instance Methods
apply?(request)
click to toggle source
# File lib/tennpipes-base/filter.rb, line 13 def apply?(request) detect = match_with_arguments?(request) || match_with_options?(request) detect ^ !@mode end
to_proc()
click to toggle source
# File lib/tennpipes-base/filter.rb, line 18 def to_proc if @args.empty? && @options.empty? block else filter = self proc { instance_eval(&filter.block) if filter.apply?(request) } end end
Private Instance Methods
match_with_arguments?(request)
click to toggle source
# File lib/tennpipes-base/filter.rb, line 33 def match_with_arguments?(request) route = request.route_obj path = request.path_info @args.any? do |argument| if argument.instance_of?(Symbol) next unless route name = route.name argument == name || name == [scoped_controller_name, argument].join(" ").to_sym else argument === path end end end
match_with_options?(request)
click to toggle source
# File lib/tennpipes-base/filter.rb, line 47 def match_with_options?(request) user_agent = request.user_agent @options.any?{|name, value| value === (name == :agent ? user_agent : request.send(name)) } end
scoped_controller_name()
click to toggle source
# File lib/tennpipes-base/filter.rb, line 29 def scoped_controller_name @scoped_controller_name ||= Array(@scoped_controller).join("_") end