Class: Knot::Dispatch::Router::Config
- Inherits:
-
Object
- Object
- Knot::Dispatch::Router::Config
- Defined in:
- lib/knot/dispatch/router/config.rb
Instance Attribute Summary collapse
-
#router_name ⇒ Object
readonly
Returns the value of attribute router_name.
Instance Method Summary collapse
- #add_filter(name, options, &block) ⇒ Object
- #applicable_filters(route) ⇒ Object
- #filters ⇒ Object
-
#initialize(router) ⇒ Config
constructor
A new instance of Config.
- #knot_template_home=(base_path) ⇒ Object
- #register_route(http_method, name, path, &block) ⇒ Object
- #reset! ⇒ Object
- #routes ⇒ Object
- #template_paths ⇒ Object
Constructor Details
#initialize(router) ⇒ Config
Returns a new instance of Config.
11 12 13 |
# File 'lib/knot/dispatch/router/config.rb', line 11 def initialize(router) @router_name = router.to_s end |
Instance Attribute Details
#router_name ⇒ Object (readonly)
Returns the value of attribute router_name.
9 10 11 |
# File 'lib/knot/dispatch/router/config.rb', line 9 def router_name @router_name end |
Instance Method Details
#add_filter(name, options, &block) ⇒ Object
27 28 29 |
# File 'lib/knot/dispatch/router/config.rb', line 27 def add_filter(name, , &block) filters << Knot::Dispatch::Filter.new(name, , &block) end |
#applicable_filters(route) ⇒ Object
42 43 44 |
# File 'lib/knot/dispatch/router/config.rb', line 42 def applicable_filters(route) filters.select {|f| f.apply_to?(route)} end |
#filters ⇒ Object
23 24 25 |
# File 'lib/knot/dispatch/router/config.rb', line 23 def filters @filters ||= [] end |
#knot_template_home=(base_path) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/knot/dispatch/router/config.rb', line 31 def knot_template_home=(base_path) @template_paths = template_paths. reject { |path| path == base_path }. map { |path| path.prepend(base_path + "/") } template_paths << base_path end |
#register_route(http_method, name, path, &block) ⇒ Object
19 20 21 |
# File 'lib/knot/dispatch/router/config.rb', line 19 def register_route(http_method, name, path, &block) routes << Knot::Dispatch::Route.new(http_method, name, path, &block) end |
#reset! ⇒ Object
46 47 48 49 |
# File 'lib/knot/dispatch/router/config.rb', line 46 def reset! @routes = [] @filters = [] end |
#routes ⇒ Object
15 16 17 |
# File 'lib/knot/dispatch/router/config.rb', line 15 def routes @routes ||= [] end |