Class: Padrino::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/routing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mode, scoped_controller, options, args, &block) ⇒ Filter

Returns a new instance of Filter.



152
153
154
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/routing.rb', line 152

def initialize(mode, scoped_controller, options, args, &block)
  @mode, @scoped_controller, @options, @args, @block = mode, scoped_controller, options, args, block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



150
151
152
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/routing.rb', line 150

def block
  @block
end

Instance Method Details

#apply?(request) ⇒ Boolean

Returns:

  • (Boolean)


156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/routing.rb', line 156

def apply?(request)
  detect = @args.any? do |arg|
    case arg
    when Symbol then request.route_obj && (request.route_obj.name == arg or request.route_obj.name == [@scoped_controller, arg].flatten.join("_").to_sym)
    else             arg === request.path_info
    end
  end || @options.any? do |name, val|
    case name
    when :agent then val === request.user_agent
    else             val === request.send(name)
    end
  end
  detect ^ !@mode
end

#to_procObject



171
172
173
174
175
176
177
178
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/routing.rb', line 171

def to_proc
  if @args.empty? && @options.empty?
    block
  else
    filter = self
    proc { instance_eval(&filter.block) if filter.apply?(request) }
  end
end