Class: Usher::Route
- Inherits:
-
Object
- Object
- Usher::Route
- Defined in:
- lib/usher/route.rb,
lib/usher/route/path.rb,
lib/usher/route/util.rb,
lib/usher/route/variable.rb,
lib/usher/route/request_method.rb
Defined Under Namespace
Modules: Util Classes: GenerateWith, Path, RequestMethod, Variable
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#default_values ⇒ Object
readonly
Returns the value of attribute default_values.
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#generate_with ⇒ Object
readonly
Returns the value of attribute generate_with.
- #grapher ⇒ Object readonly
-
#match_partially ⇒ Object
readonly
Returns the value of attribute match_partially.
-
#named ⇒ Object
readonly
Returns the value of attribute named.
-
#parent_route ⇒ Object
Returns the value of attribute parent_route.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#requirements ⇒ Object
readonly
Returns the value of attribute requirements.
-
#router ⇒ Object
Returns the value of attribute router.
Instance Method Summary collapse
- #dup ⇒ Object
- #find_matching_path(params) ⇒ Object
-
#initialize(parsed_paths, router, conditions, requirements, default_values, generate_with, match_partially) ⇒ Route
constructor
A new instance of Route.
- #match_partially! ⇒ Object
-
#name(name) ⇒ Object
Sets route as referenceable from
name
. - #partial_match? ⇒ Boolean
-
#to(options = nil, &block) ⇒ Object
Sets
options
on a route.
Constructor Details
#initialize(parsed_paths, router, conditions, requirements, default_values, generate_with, match_partially) ⇒ Route
Returns a new instance of Route.
15 16 17 18 19 |
# File 'lib/usher/route.rb', line 15 def initialize(parsed_paths, router, conditions, requirements, default_values, generate_with, match_partially) @paths = parsed_paths.collect {|path| Path.new(self, path)} @router, @requirements, @conditions, @default_values, @match_partially = router, requirements, conditions, default_values, match_partially @generate_with = GenerateWith.new(generate_with[:scheme], generate_with[:port], generate_with[:host]) if generate_with end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
8 9 10 |
# File 'lib/usher/route.rb', line 8 def conditions @conditions end |
#default_values ⇒ Object (readonly)
Returns the value of attribute default_values.
8 9 10 |
# File 'lib/usher/route.rb', line 8 def default_values @default_values end |
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
8 9 10 |
# File 'lib/usher/route.rb', line 8 def destination @destination end |
#generate_with ⇒ Object (readonly)
Returns the value of attribute generate_with.
8 9 10 |
# File 'lib/usher/route.rb', line 8 def generate_with @generate_with end |
#grapher ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/usher/route.rb', line 21 def grapher unless @grapher @grapher = Grapher.new @grapher.add_route(self) end @grapher end |
#match_partially ⇒ Object (readonly)
Returns the value of attribute match_partially.
8 9 10 |
# File 'lib/usher/route.rb', line 8 def match_partially @match_partially end |
#named ⇒ Object (readonly)
Returns the value of attribute named.
8 9 10 |
# File 'lib/usher/route.rb', line 8 def named @named end |
#parent_route ⇒ Object
Returns the value of attribute parent_route.
11 12 13 |
# File 'lib/usher/route.rb', line 11 def parent_route @parent_route end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
8 9 10 |
# File 'lib/usher/route.rb', line 8 def paths @paths end |
#requirements ⇒ Object (readonly)
Returns the value of attribute requirements.
8 9 10 |
# File 'lib/usher/route.rb', line 8 def requirements @requirements end |
#router ⇒ Object
Returns the value of attribute router.
11 12 13 |
# File 'lib/usher/route.rb', line 11 def router @router end |
Instance Method Details
#dup ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/usher/route.rb', line 29 def dup result = super result.instance_eval do @grapher = nil end result end |
#find_matching_path(params) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/usher/route.rb', line 37 def find_matching_path(params) if params.nil? || params.empty? matching_path = @paths.first else matching_path = @paths.size == 1 ? @paths.first : grapher.find_matching_path(params) end if parent_route matching_path = parent_route.find_matching_path(params).merge(matching_path) matching_path.route = self end matching_path end |
#match_partially! ⇒ Object
81 82 83 84 |
# File 'lib/usher/route.rb', line 81 def match_partially! @match_partially = true self end |
#name(name) ⇒ Object
75 76 77 78 79 |
# File 'lib/usher/route.rb', line 75 def name(name) @named = name @router.name(name, self) self end |
#partial_match? ⇒ Boolean
86 87 88 |
# File 'lib/usher/route.rb', line 86 def partial_match? @match_partially end |
#to(options = nil, &block) ⇒ Object
Sets options
on a route. Returns self
.
Request = Struct.new(:path)
set = Usher.new
route = set.add_route('/test')
route.to(:controller => 'testing', :action => 'index')
set.recognize(Request.new('/test')).first.params => {:controller => 'testing', :action => 'index'}
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/usher/route.rb', line 59 def to( = nil, &block) raise "cannot set destination as block and argument" if block_given? && @destination = if block_given? block else .parent_route = self if .respond_to?(:parent_route=) end self end |