Class: ActionDispatch::Routing::Mapper::Mapping
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::Mapper::Mapping
- Defined in:
- lib/action_dispatch/routing/mapper.rb
Overview
:nodoc:
Constant Summary collapse
- ANCHOR_CHARACTERS_REGEX =
%r{\A(\\A|\^)|(\\Z|\\z|\$)\Z}
- OPTIONAL_FORMAT_REGEX =
%r{(?:\(\.:format\)+|\.:format|/)\Z}
- JOINED_SEPARATORS =
:nodoc:
SEPARATORS.join
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#default_action ⇒ Object
readonly
Returns the value of attribute default_action.
-
#default_controller ⇒ Object
readonly
Returns the value of attribute default_controller.
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#required_defaults ⇒ Object
readonly
Returns the value of attribute required_defaults.
-
#requirements ⇒ Object
readonly
Returns the value of attribute requirements.
-
#scope_options ⇒ Object
readonly
Returns the value of attribute scope_options.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Class Method Summary collapse
- .build(scope, set, ast, controller, default_action, to, via, formatted, options_constraints, anchor, options) ⇒ Object
- .check_via(via) ⇒ Object
- .normalize_path(path, format) ⇒ Object
- .optional_format?(path, format) ⇒ Boolean
Instance Method Summary collapse
- #application ⇒ Object
- #conditions ⇒ Object
-
#initialize(set, ast, defaults, controller, default_action, modyoule, to, formatted, scope_constraints, scope_options, blocks, via, options_constraints, anchor, options) ⇒ Mapping
constructor
A new instance of Mapping.
- #make_route(name, precedence) ⇒ Object
- #path ⇒ Object
Constructor Details
#initialize(set, ast, defaults, controller, default_action, modyoule, to, formatted, scope_constraints, scope_options, blocks, via, options_constraints, anchor, options) ⇒ Mapping
Returns a new instance of Mapping.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/action_dispatch/routing/mapper.rb', line 114 def initialize(set, ast, defaults, controller, default_action, modyoule, to, formatted, scope_constraints, , blocks, via, , anchor, ) @defaults = defaults @set = set @to = intern(to) @default_controller = intern(controller) @default_action = intern(default_action) @ast = ast @anchor = anchor @via = via @internal = .delete(:internal) @scope_options = path_params = ast.find_all(&:symbol?).map(&:to_sym) = (, formatted, ast) = (, path_params, modyoule) = constraints(, path_params) constraints = scope_constraints.merge Hash[[:constraints] || []] if .is_a?(Hash) @defaults = Hash[.find_all { |key, default| URL_OPTIONS.include?(key) && (String === default || Integer === default) }].merge @defaults @blocks = blocks constraints.merge! else @blocks = blocks() end requirements, conditions = split_constraints path_params, constraints verify_regexp_requirements requirements.map(&:last).grep(Regexp) formats = normalize_format(formatted) @requirements = formats[:requirements].merge Hash[requirements] @conditions = Hash[conditions] @defaults = formats[:defaults].merge(@defaults).merge(normalize_defaults()) if path_params.include?(:action) && !@requirements.key?(:action) @defaults[:action] ||= "index" end @required_defaults = ([:required_defaults] || []).map(&:first) end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
73 74 75 |
# File 'lib/action_dispatch/routing/mapper.rb', line 73 def ast @ast end |
#default_action ⇒ Object (readonly)
Returns the value of attribute default_action.
73 74 75 |
# File 'lib/action_dispatch/routing/mapper.rb', line 73 def default_action @default_action end |
#default_controller ⇒ Object (readonly)
Returns the value of attribute default_controller.
73 74 75 |
# File 'lib/action_dispatch/routing/mapper.rb', line 73 def default_controller @default_controller end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
73 74 75 |
# File 'lib/action_dispatch/routing/mapper.rb', line 73 def defaults @defaults end |
#required_defaults ⇒ Object (readonly)
Returns the value of attribute required_defaults.
73 74 75 |
# File 'lib/action_dispatch/routing/mapper.rb', line 73 def required_defaults @required_defaults end |
#requirements ⇒ Object (readonly)
Returns the value of attribute requirements.
73 74 75 |
# File 'lib/action_dispatch/routing/mapper.rb', line 73 def requirements @requirements end |
#scope_options ⇒ Object (readonly)
Returns the value of attribute scope_options.
73 74 75 |
# File 'lib/action_dispatch/routing/mapper.rb', line 73 def @scope_options end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
73 74 75 |
# File 'lib/action_dispatch/routing/mapper.rb', line 73 def to @to end |
Class Method Details
.build(scope, set, ast, controller, default_action, to, via, formatted, options_constraints, anchor, options) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/action_dispatch/routing/mapper.rb', line 76 def self.build(scope, set, ast, controller, default_action, to, via, formatted, , anchor, ) = scope[:options].merge() if scope[:options] defaults = (scope[:defaults] || {}).dup scope_constraints = scope[:constraints] || {} = scope[:options] || {} new set, ast, defaults, controller, default_action, scope[:module], to, formatted, scope_constraints, , scope[:blocks] || [], via, , anchor, end |
.check_via(via) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/action_dispatch/routing/mapper.rb', line 86 def self.check_via(via) if via.empty? msg = "You should not use the `match` method in your router without specifying an HTTP method.\n" \ "If you want to expose your action to both GET and POST, add `via: [:get, :post]` option.\n" \ "If you want to expose your action to GET, use `get` in the router:\n" \ " Instead of: match \"controller#action\"\n" \ " Do: get \"controller#action\"" raise ArgumentError, msg end via end |
.normalize_path(path, format) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/action_dispatch/routing/mapper.rb', line 98 def self.normalize_path(path, format) path = Mapper.normalize_path(path) if format == true "#{path}.:format" elsif optional_format?(path, format) "#{path}(.:format)" else path end end |
.optional_format?(path, format) ⇒ Boolean
110 111 112 |
# File 'lib/action_dispatch/routing/mapper.rb', line 110 def self.optional_format?(path, format) format != false && path !~ OPTIONAL_FORMAT_REGEX end |
Instance Method Details
#application ⇒ Object
168 169 170 |
# File 'lib/action_dispatch/routing/mapper.rb', line 168 def application app(@blocks) end |
#conditions ⇒ Object
176 177 178 |
# File 'lib/action_dispatch/routing/mapper.rb', line 176 def conditions build_conditions @conditions, @set.request_class end |
#make_route(name, precedence) ⇒ Object
163 164 165 166 |
# File 'lib/action_dispatch/routing/mapper.rb', line 163 def make_route(name, precedence) Journey::Route.new(name, application, path, conditions, required_defaults, defaults, request_method, precedence, , @internal) end |
#path ⇒ Object
172 173 174 |
# File 'lib/action_dispatch/routing/mapper.rb', line 172 def path build_path @ast, requirements, @anchor end |