Class: Knot::Dispatch::Filter
- Inherits:
-
Object
- Object
- Knot::Dispatch::Filter
- Defined in:
- lib/knot/dispatch/filter.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
Instance Method Summary collapse
- #apply_to?(route) ⇒ Boolean
- #except ⇒ Object
-
#initialize(name, options = {}, &block) ⇒ Filter
constructor
A new instance of Filter.
- #only ⇒ Object
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, = {}, &block) @name = name @options = {:only => [], :except => []}.merge() @block = block end |
Instance Attribute Details
#block ⇒ Object (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
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 |
#except ⇒ Object
23 24 25 |
# File 'lib/knot/dispatch/filter.rb', line 23 def except @options[:except] end |
#only ⇒ Object
19 20 21 |
# File 'lib/knot/dispatch/filter.rb', line 19 def only @options[:only] end |