Class: Knot::Dispatch::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/knot/dispatch/filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}, &block) ⇒ Filter

Returns a new instance of Filter.



7
8
9
10
11
# File 'lib/knot/dispatch/filter.rb', line 7

def initialize(name, options = {}, &block)
  @name = name
  @options = {:only => [], :except => []}.merge(options)
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



5
6
7
# File 'lib/knot/dispatch/filter.rb', line 5

def block
  @block
end

Instance Method Details

#apply_to?(route) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/knot/dispatch/filter.rb', line 13

def apply_to?(route)
  (only.empty? && except.empty?) || 
    (!only.empty? && only.include?(route.name)) ||
    (!except.empty? && !except.include?(route.name))
end

#exceptObject



23
24
25
# File 'lib/knot/dispatch/filter.rb', line 23

def except
  @options[:except]
end

#onlyObject



19
20
21
# File 'lib/knot/dispatch/filter.rb', line 19

def only
  @options[:only]
end