Class: ActionDispatch::Routing::Mapper::Mapping
- Defined in:
- actionpack/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.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#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:, controller:, default_action:, to:, formatted:, via:, options_constraints:, anchor:, scope_params:, options:) ⇒ Mapping
constructor
A new instance of Mapping.
- #make_route(name, precedence) ⇒ Object
Constructor Details
#initialize(set:, ast:, controller:, default_action:, to:, formatted:, via:, options_constraints:, anchor:, scope_params:, options:) ⇒ Mapping
Returns a new instance of Mapping.
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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 132 def initialize(set:, ast:, controller:, default_action:, to:, formatted:, via:, options_constraints:, anchor:, scope_params:, options:) @defaults = scope_params[:defaults] @set = set @to = intern(to) @default_controller = intern(controller) @default_action = intern(default_action) @anchor = anchor @via = via @internal = .delete(:internal) @scope_options = scope_params[:options] ast = Journey::Ast.new(ast, formatted) = ast..merge!() = (, ast.path_params, scope_params[:module]) = constraints(, ast.path_params) constraints = scope_params[: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 = scope_params[:blocks] constraints.merge! else @blocks = blocks() end requirements, conditions = split_constraints ast.path_params, constraints verify_regexp_requirements requirements, ast. formats = normalize_format(formatted) @requirements = formats[:requirements].merge Hash[requirements] @conditions = Hash[conditions] @defaults = formats[:defaults].merge(@defaults).merge(normalize_defaults()) if ast.path_params.include?(:action) && !@requirements.key?(:action) @defaults[:action] ||= "index" end @required_defaults = ([:required_defaults] || []).map(&:first) ast.requirements = @requirements @path = Journey::Path::Pattern.new(ast, @requirements, JOINED_SEPARATORS, @anchor) end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
87 88 89 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 87 def ast @ast end |
#default_action ⇒ Object (readonly)
Returns the value of attribute default_action.
87 88 89 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 87 def default_action @default_action end |
#default_controller ⇒ Object (readonly)
Returns the value of attribute default_controller.
87 88 89 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 87 def default_controller @default_controller end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
87 88 89 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 87 def defaults @defaults end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
87 88 89 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 87 def path @path end |
#required_defaults ⇒ Object (readonly)
Returns the value of attribute required_defaults.
87 88 89 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 87 def required_defaults @required_defaults end |
#requirements ⇒ Object (readonly)
Returns the value of attribute requirements.
87 88 89 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 87 def requirements @requirements end |
#scope_options ⇒ Object (readonly)
Returns the value of attribute scope_options.
87 88 89 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 87 def @scope_options end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
87 88 89 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 87 def to @to end |
Class Method Details
.build(scope, set, ast, controller, default_action, to, via, formatted, options_constraints, anchor, options) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 90 def self.build(scope, set, ast, controller, default_action, to, via, formatted, , anchor, ) scope_params = { blocks: scope[:blocks] || [], constraints: scope[:constraints] || {}, defaults: (scope[:defaults] || {}).dup, module: scope[:module], options: scope[:options] || {} } new set: set, ast: ast, controller: controller, default_action: default_action, to: to, formatted: formatted, via: via, options_constraints: , anchor: anchor, scope_params: scope_params, options: scope_params[:options].merge() end |
.check_via(via) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 104 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
116 117 118 119 120 121 122 123 124 125 126 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 116 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
128 129 130 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 128 def self.optional_format?(path, format) format != false && !path.match?(OPTIONAL_FORMAT_REGEX) end |
Instance Method Details
#application ⇒ Object
190 191 192 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 190 def application app(@blocks) end |
#conditions ⇒ Object
194 195 196 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 194 def conditions build_conditions @conditions, @set.request_class end |
#make_route(name, precedence) ⇒ Object
183 184 185 186 187 188 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 183 def make_route(name, precedence) Journey::Route.new(name: name, app: application, path: path, constraints: conditions, required_defaults: required_defaults, defaults: defaults, request_method_match: request_method, precedence: precedence, scope_options: , internal: @internal, source_location: route_source_location) end |