class Tension::Environment

This class describes routes and controller contexts, and through those contexts the assets to be included in templates.

Attributes

assets[R]
controllers[R]

Public Instance Methods

contexts() click to toggle source

A Hash mapping controller paths to Contexts.

# File lib/tension/environment.rb, line 30
def contexts
  @contexts ||= Hash.new
end
find_asset(logical_path) click to toggle source

Returns a Sprockets::Asset for the given logical path. Will load assets cached from a manifest if available, but in development falls back to the Sprockets::Index as assets may be under development.

# File lib/tension/environment.rb, line 20
def find_asset(logical_path)
  if assets_cached?
    assets[logical_path]
  else
    Rails.application.assets.find_asset(logical_path)
  end
end
find_context(key) click to toggle source

Loads a Context for the specified controller path.

# File lib/tension/environment.rb, line 12
def find_context(key)
  fetch( Tension::Utils.controller_path(key) )
end

Private Instance Methods

configured_get_defaults() click to toggle source

Routing defaults (including controller path and action name) for all configured GET routes.

# File lib/tension/environment.rb, line 58
def configured_get_defaults
  @configured_get_defaults ||= Rails.application.routes.routes.map do |route|
    route.defaults if route.verb.match("GET") && !route.defaults.empty?
  end.compact
end
fetch(path) click to toggle source
# File lib/tension/environment.rb, line 41
def fetch(path)
  (contexts[path] || store(path)) if path.present?
end
store(path) click to toggle source
# File lib/tension/environment.rb, line 45
def store(path)
  contexts[path] ||= Context.new(path) if valid_route?(path)
end
valid_route?(controller) click to toggle source
# File lib/tension/environment.rb, line 49
def valid_route?(controller)
  configured_get_defaults.find do |default|
    default[:controller] == controller
  end
end