Class: ActionController::Routing::Optimisation::PositionalArgumentsWithAdditionalParams

Inherits:
PositionalArguments show all
Defined in:
actionpack/lib/action_controller/routing/optimisations.rb

Overview

This case is mostly the same as the positional arguments case above, but it supports additional query parameters as the last argument

Constant Summary

Constants inherited from Optimiser

Optimiser::GLOBAL_GUARD_CONDITIONS

Instance Attribute Summary

Attributes inherited from Optimiser

#kind, #route

Instance Method Summary collapse

Methods inherited from Optimiser

#initialize, #source_code

Constructor Details

This class inherits a constructor from ActionController::Routing::Optimisation::Optimiser

Instance Method Details

#applicable?Boolean

To avoid generating “localhost/?host=foo.example.com” we can't use this optimisation on routes without any segments

Returns:

  • (Boolean)


122
123
124
# File 'actionpack/lib/action_controller/routing/optimisations.rb', line 122

def applicable?
  super && route.segment_keys.size > 0
end

#generation_codeObject

This case uses almost the same code as positional arguments, but add a question mark and args.last.to_query on the end, unless the last arg is empty



116
117
118
# File 'actionpack/lib/action_controller/routing/optimisations.rb', line 116

def generation_code
  super.insert(-2, '#{\'?\' + args.last.to_query unless args.last.empty?}')
end

#guard_conditionsObject



108
109
110
111
# File 'actionpack/lib/action_controller/routing/optimisations.rb', line 108

def guard_conditions
  ["args.size == #{route.segment_keys.size + 1}"] +
  UrlRewriter::RESERVED_OPTIONS.collect{ |key| "!args.last.has_key?(:#{key})" }
end