Class: ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper

Inherits:
Object
  • Object
show all
Defined in:
actionpack/lib/action_dispatch/routing/route_set.rb

Overview

:nodoc:

Direct Known Subclasses

OptimizedUrlHelper

Defined Under Namespace

Classes: OptimizedUrlHelper

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(route, options) ⇒ UrlHelper

Returns a new instance of UrlHelper.



227
228
229
230
231
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 227

def initialize(route, options)
  @options      = options
  @segment_keys = route.segment_keys
  @route        = route
end

Class Method Details

.create(route, options) ⇒ Object



149
150
151
152
153
154
155
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 149

def self.create(route, options)
  if optimize_helper?(route)
    OptimizedUrlHelper.new(route, options)
  else
    new route, options
  end
end

.optimize_helper?(route) ⇒ Boolean

Returns:

  • (Boolean)


157
158
159
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 157

def self.optimize_helper?(route)
  route.requirements.except(:controller, :action).empty?
end

Instance Method Details

#call(t, args) ⇒ Object



233
234
235
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 233

def call(t, args)
  t.url_for(handle_positional_args(t, args, @options, @segment_keys))
end

#handle_positional_args(t, args, options, keys) ⇒ Object



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 237

def handle_positional_args(t, args, options, keys)
  inner_options = args.extract_options!
  result = options.dup

  if args.size > 0
    if args.size < keys.size - 1 # take format into account
      keys -= t.url_options.keys if t.respond_to?(:url_options)
      keys -= options.keys
    end
    keys -= inner_options.keys
    result.merge!(Hash[keys.zip(args)])
  end

  result.merge!(inner_options)
end