Class: Padrino::Filter

Inherits:
Object show all
Defined in:
padrino-core/lib/padrino-core/filter.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.



5
6
7
8
9
10
11
# File 'padrino-core/lib/padrino-core/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

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



3
4
5
# File 'padrino-core/lib/padrino-core/filter.rb', line 3

def block
  @block
end

Instance Method Details

#apply?(request) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
# File 'padrino-core/lib/padrino-core/filter.rb', line 13

def apply?(request)
  detect = match_with_arguments?(request) || match_with_options?(request)
  detect ^ !@mode
end

#to_procObject



18
19
20
21
22
23
24
25
# File 'padrino-core/lib/padrino-core/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