Class: ActionController::Routing::Optimisation::Optimiser

Inherits:
Object
  • Object
show all
Defined in:
lib/action_controller/routing/optimisations.rb

Direct Known Subclasses

PositionalArguments

Constant Summary collapse

GLOBAL_GUARD_CONDITIONS =
[
"(!defined?(default_url_options) || default_url_options.blank?)",
"(!defined?(controller.default_url_options) || controller.default_url_options.blank?)",
"defined?(request)",
"request"
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(route, kind) ⇒ Optimiser

Returns a new instance of Optimiser.



30
31
32
33
# File 'lib/action_controller/routing/optimisations.rb', line 30

def initialize(route, kind)
  @route = route
  @kind  = kind
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



22
23
24
# File 'lib/action_controller/routing/optimisations.rb', line 22

def kind
  @kind
end

#routeObject (readonly)

Returns the value of attribute route.



22
23
24
# File 'lib/action_controller/routing/optimisations.rb', line 22

def route
  @route
end

Instance Method Details

#applicable?Boolean

Temporarily disabled :url optimisation pending proper solution to Issues around request.host etc.

Returns:

  • (Boolean)


54
55
56
# File 'lib/action_controller/routing/optimisations.rb', line 54

def applicable?
  true
end

#generation_codeObject



39
40
41
# File 'lib/action_controller/routing/optimisations.rb', line 39

def generation_code
  'nil'
end

#guard_conditionsObject



35
36
37
# File 'lib/action_controller/routing/optimisations.rb', line 35

def guard_conditions
  ["false"]
end

#source_codeObject



43
44
45
46
47
48
49
50
# File 'lib/action_controller/routing/optimisations.rb', line 43

def source_code
  if applicable?
    guard_condition = (GLOBAL_GUARD_CONDITIONS + guard_conditions).join(" && ")
    "return #{generation_code} if #{guard_condition}\n"
  else
    "\n"
  end
end