Class: ActionDispatch::Journey::Format
- Inherits:
-
Object
- Object
- ActionDispatch::Journey::Format
- Defined in:
- lib/action_dispatch/journey/visitors.rb
Defined Under Namespace
Classes: Parameter
Constant Summary collapse
- ESCAPE_PATH =
->(value) { Router::Utils.escape_path(value) }
- ESCAPE_SEGMENT =
->(value) { Router::Utils.escape_segment(value) }
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(hash) ⇒ Object
-
#initialize(parts) ⇒ Format
constructor
A new instance of Format.
Constructor Details
#initialize(parts) ⇒ Format
Returns a new instance of Format.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/action_dispatch/journey/visitors.rb', line 22 def initialize(parts) @parts = parts @children = [] @parameters = [] parts.each_with_index do |object, i| case object when Journey::Format @children << i when Parameter @parameters << i end end end |
Class Method Details
.required_path(symbol) ⇒ Object
14 15 16 |
# File 'lib/action_dispatch/journey/visitors.rb', line 14 def self.required_path(symbol) Parameter.new symbol, ESCAPE_PATH end |
.required_segment(symbol) ⇒ Object
18 19 20 |
# File 'lib/action_dispatch/journey/visitors.rb', line 18 def self.required_segment(symbol) Parameter.new symbol, ESCAPE_SEGMENT end |
Instance Method Details
#evaluate(hash) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/action_dispatch/journey/visitors.rb', line 37 def evaluate(hash) parts = @parts.dup @parameters.each do |index| param = parts[index] value = hash[param.name] return "" unless value parts[index] = param.escape value end @children.each { |index| parts[index] = parts[index].evaluate(hash) } parts.join end |