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/static.rb,
lib/usher/route/variable.rb,
lib/usher/route/request_method.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Util Classes: CompoundDestination, GenerateWith, Path, RequestMethod, Static, 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
(also: #partial_match?)
readonly
Returns the value of attribute match_partially.
-
#named ⇒ Object
readonly
Returns the value of attribute named.
-
#original_path ⇒ Object
readonly
Returns the value of attribute original_path.
-
#parent_route ⇒ Object
Returns the value of attribute parent_route.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#recognizable ⇒ Object
Returns the value of attribute recognizable.
-
#requirements ⇒ Object
readonly
Returns the value of attribute requirements.
-
#router ⇒ Object
Returns the value of attribute router.
-
#when_proc ⇒ Object
readonly
Returns the value of attribute when_proc.
Instance Method Summary collapse
- #==(other_route) ⇒ Object
- #destination_keys ⇒ Object
- #dup ⇒ Object
- #find_matching_path(params) ⇒ Object
-
#initialize(original_path, parsed_paths, router, conditions, requirements, default_values, generate_with, match_partially, priority) ⇒ Route
constructor
A new instance of Route.
- #inspect ⇒ Object
- #match_partially! ⇒ Object
-
#name(name) ⇒ self
Sets route as referenceable from ‘name`.
- #recognizable! ⇒ Object
- #recognizable? ⇒ Boolean
-
#to(*args, &block) ⇒ self
Sets destination on a route.
- #to_s ⇒ Object
- #unrecognizable! ⇒ Object
- #when(&block) ⇒ Object
Constructor Details
#initialize(original_path, parsed_paths, router, conditions, requirements, default_values, generate_with, match_partially, priority) ⇒ Route
Returns a new instance of Route.
24 25 26 27 28 29 |
# File 'lib/usher/route.rb', line 24 def initialize(original_path, parsed_paths, router, conditions, requirements, default_values, generate_with, match_partially, priority) @original_path, @router, @requirements, @conditions, @default_values, @match_partially, @priority = original_path, router, requirements, conditions, default_values, match_partially, priority @recognizable = true @paths = parsed_paths.collect {|path| Path.new(self, path)} @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.
9 10 11 |
# File 'lib/usher/route.rb', line 9 def conditions @conditions end |
#default_values ⇒ Object (readonly)
Returns the value of attribute default_values.
9 10 11 |
# File 'lib/usher/route.rb', line 9 def default_values @default_values end |
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
9 10 11 |
# File 'lib/usher/route.rb', line 9 def destination @destination end |
#generate_with ⇒ Object (readonly)
Returns the value of attribute generate_with.
9 10 11 |
# File 'lib/usher/route.rb', line 9 def generate_with @generate_with end |
#grapher ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/usher/route.rb', line 55 def grapher unless @grapher @grapher = Grapher.new(router) @grapher.add_route(self) end @grapher end |
#match_partially ⇒ Object (readonly) Also known as: partial_match?
Returns the value of attribute match_partially.
9 10 11 |
# File 'lib/usher/route.rb', line 9 def match_partially @match_partially end |
#named ⇒ Object (readonly)
Returns the value of attribute named.
9 10 11 |
# File 'lib/usher/route.rb', line 9 def named @named end |
#original_path ⇒ Object (readonly)
Returns the value of attribute original_path.
9 10 11 |
# File 'lib/usher/route.rb', line 9 def original_path @original_path end |
#parent_route ⇒ Object
Returns the value of attribute parent_route.
10 11 12 |
# File 'lib/usher/route.rb', line 10 def parent_route @parent_route end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
9 10 11 |
# File 'lib/usher/route.rb', line 9 def paths @paths end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
9 10 11 |
# File 'lib/usher/route.rb', line 9 def priority @priority end |
#recognizable ⇒ Object
Returns the value of attribute recognizable.
10 11 12 |
# File 'lib/usher/route.rb', line 10 def recognizable @recognizable end |
#requirements ⇒ Object (readonly)
Returns the value of attribute requirements.
9 10 11 |
# File 'lib/usher/route.rb', line 9 def requirements @requirements end |
#router ⇒ Object
Returns the value of attribute router.
10 11 12 |
# File 'lib/usher/route.rb', line 10 def router @router end |
#when_proc ⇒ Object (readonly)
Returns the value of attribute when_proc.
9 10 11 |
# File 'lib/usher/route.rb', line 9 def when_proc @when_proc end |
Instance Method Details
#==(other_route) ⇒ Object
18 19 20 21 22 |
# File 'lib/usher/route.rb', line 18 def ==(other_route) if other_route.is_a?(Route) original_path == other_route.original_path && requirements == other_route.requirements && conditions == other_route.conditions && match_partially == other_route.match_partially && recognizable == other_route.recognizable && parent_route == other_route.parent_route && generate_with == other_route.generate_with end end |
#destination_keys ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/usher/route.rb', line 36 def destination_keys @destination_keys ||= case when Hash destination.keys when CompoundDestination destination..keys else nil end end |
#dup ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/usher/route.rb', line 77 def dup result = super result.instance_eval do @grapher = nil end result end |
#find_matching_path(params) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/usher/route.rb', line 85 def find_matching_path(params) significant_param_keys = (params && params.is_a?(Hash)) ? (params.keys & grapher.significant_keys) : nil matching_path = if significant_param_keys.nil? || significant_param_keys.empty? @paths.first else @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 |
#inspect ⇒ Object
47 48 49 |
# File 'lib/usher/route.rb', line 47 def inspect "#<Usher:Route:0x%x @paths=[%s]>" % [self.object_id, paths.collect{|p| p.parts ? p.parts.join : 'nil'}.join(', ')] end |
#match_partially! ⇒ Object
150 151 152 153 |
# File 'lib/usher/route.rb', line 150 def match_partially! @match_partially = true self end |
#name(name) ⇒ self
Sets route as referenceable from ‘name`
144 145 146 147 148 |
# File 'lib/usher/route.rb', line 144 def name(name) @named = name @router.name(name, self) self end |
#recognizable! ⇒ Object
68 69 70 71 |
# File 'lib/usher/route.rb', line 68 def recognizable! @recognizable = true self end |
#recognizable? ⇒ Boolean
73 74 75 |
# File 'lib/usher/route.rb', line 73 def recognizable? @recognizable end |
#to(*args, &block) ⇒ self
Sets destination on a route.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/usher/route.rb', line 118 def to(*args, &block) if !args.empty? && block @destination = CompoundDestination.new(args, block, args.last.is_a?(Hash) ? args.pop : {}) elsif block.nil? case args.size when 0 raise "destination should be set as something" when 1 @destination = args.first else @destination = CompoundDestination.new(args, nil, args.last.is_a?(Hash) ? args.pop : {}) end else @destination = block end args.first.parent_route = self if args.first.respond_to?(:parent_route=) self end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/usher/route.rb', line 51 def to_s inspect end |
#unrecognizable! ⇒ Object
63 64 65 66 |
# File 'lib/usher/route.rb', line 63 def unrecognizable! @recognizable = false self end |
#when(&block) ⇒ Object
31 32 33 34 |
# File 'lib/usher/route.rb', line 31 def when(&block) @when_proc = block self end |