123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::Journey::Ast

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: actionpack/lib/action_dispatch/journey/nodes/node.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(tree, formatted) ⇒ Ast

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/nodes/node.rb', line 13

def initialize(tree, formatted)
  @tree = tree
  @path_params = []
  @names = []
  @symbols = []
  @stars = []
  @terminals = []
  @wildcard_options = {}

  visit_tree(formatted)
end

Instance Attribute Details

#glob?Boolean (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/nodes/node.rb', line 38

def glob?
  stars.any?
end

#names (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/nodes/node.rb', line 10

attr_reader :names, :path_params, :tree, :wildcard_options, :terminals

#path_params (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/nodes/node.rb', line 10

attr_reader :names, :path_params, :tree, :wildcard_options, :terminals

#requirements=(requirements) (writeonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/nodes/node.rb', line 25

def requirements=(requirements)
  # inject any regexp requirements for `star` nodes so they can be determined
  # nullable, which requires knowing if the regex accepts an empty string.
  (symbols + stars).each do |node|
    re = requirements[node.to_sym]
    node.regexp = re if re
  end
end

#root (readonly)

Alias for #tree.

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/nodes/node.rb', line 11

alias :root :tree

#route=(route) (writeonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/nodes/node.rb', line 34

def route=(route)
  terminals.each { |n| n.memo = route }
end

#stars (readonly, private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/nodes/node.rb', line 43

attr_reader :symbols, :stars

#symbols (readonly, private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/nodes/node.rb', line 43

attr_reader :symbols, :stars

#terminals (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/nodes/node.rb', line 10

attr_reader :names, :path_params, :tree, :wildcard_options, :terminals

#tree (readonly) Also known as: #root

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/nodes/node.rb', line 10

attr_reader :names, :path_params, :tree, :wildcard_options, :terminals

#wildcard_options (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/nodes/node.rb', line 10

attr_reader :names, :path_params, :tree, :wildcard_options, :terminals

Instance Method Details

#visit_tree(formatted) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/nodes/node.rb', line 45

def visit_tree(formatted)
  tree.each do |node|
    if node.symbol?
      path_params << node.to_sym
      names << node.name
      symbols << node
    elsif node.star?
      stars << node

      if formatted != false
        # Add a constraint for wildcard route to make it non-greedy and match the
        # optional format part of the route by default.
        wildcard_options[node.name.to_sym] ||= /.+?/m
      end
    end

    if node.terminal?
      terminals << node
    end
  end
end