Class: Knot::Dispatch::Router::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (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, options, &block)
  filters << Knot::Dispatch::Filter.new(name, options, &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

#filtersObject



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

#routesObject



15
16
17
# File 'lib/knot/dispatch/router/config.rb', line 15

def routes
  @routes ||= []
end

#template_pathsObject



38
39
40
# File 'lib/knot/dispatch/router/config.rb', line 38

def template_paths
  @template_paths ||= [Knot::Util.to_snake(router_name)]
end