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

Inherits:
Object
  • Object
show all
Defined in:
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.



223
224
225
226
227
# File 'lib/action_dispatch/routing/route_set.rb', line 223

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

Class Method Details

.create(route, options) ⇒ Object



151
152
153
154
155
156
157
# File 'lib/action_dispatch/routing/route_set.rb', line 151

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)


159
160
161
# File 'lib/action_dispatch/routing/route_set.rb', line 159

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

Instance Method Details

#call(t, args) ⇒ Object



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

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

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



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/action_dispatch/routing/route_set.rb', line 233

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