Class: ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper::OptimizedUrlHelper
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper
|
Defined in: | actionpack/lib/action_dispatch/routing/route_set.rb |
Class Method Summary
Instance Attribute Summary
- #arg_size readonly
::ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper
- Inherited
Instance Method Summary
- #call(t, method_name, args, inner_options, url_strategy)
- #optimize_routes_generation?(t) ⇒ Boolean private
- #optimized_helper(args) private
- #parameterize_args(args) private
- #raise_generation_error(args) private
::ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper
- Inherited
Constructor Details
.new(route, options, route_name) ⇒ OptimizedUrlHelper
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 208
def initialize(route, , route_name) super @required_parts = @route.required_parts @arg_size = @required_parts.size end
Instance Attribute Details
#arg_size (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 206
attr_reader :arg_size
Instance Method Details
#call(t, method_name, args, inner_options, url_strategy)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 214
def call(t, method_name, args, , url_strategy) if args.size == arg_size && ! && optimize_routes_generation?(t) = t. .merge @options path = optimized_helper(args) path << "/" if [:trailing_slash] && !path.end_with?("/") [:path] = path original_script_name = .delete(:original_script_name) script_name = t._routes.find_script_name( ) if original_script_name script_name = original_script_name + script_name end [:script_name] = script_name url_strategy.call else super end end
#optimize_routes_generation?(t) ⇒ Boolean
(private)
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 245
def optimize_routes_generation?(t) t.send(:optimize_routes_generation?) end
#optimized_helper(args) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 237
def optimized_helper(args) params = parameterize_args(args) do raise_generation_error(args) end @route.format params end
#parameterize_args(args) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 249
def parameterize_args(args) params = {} @arg_size.times { |i| key = @required_parts[i] value = args[i].to_param yield key if value.nil? || value.empty? params[key] = value } params end
#raise_generation_error(args) (private)
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 260
def raise_generation_error(args) missing_keys = [] params = parameterize_args(args) { |missing_key| missing_keys << missing_key } constraints = Hash[@route.requirements.merge(params).sort_by { |k, v| k.to_s }] = +"No route matches #{constraints.inspect}" << ", missing required keys: #{missing_keys.sort.inspect}" raise ActionController::UrlGenerationError, end