class RoadForest::Dispatcher

Attributes

services[RW]
trace_by_default[RW]

Public Class Methods

new(services) click to toggle source
Calls superclass method
# File lib/roadforest/application/dispatcher.rb, line 8
def initialize(services)
  super(method(:create_resource))
  @services = services
  @route_names = {}
  @route_mappings = []
  @trace_by_default = false
end

Public Instance Methods

add(name=nil, path_spec=nil, resource_type=nil, interface_class=nil)
Alias for: add_route
add_route(name=nil, path_spec=nil, resource_type=nil, interface_class=nil) { |binder| ... } click to toggle source

Add a named route to the dispatcher - the 90% case is handled by passing arguments in, but more control is available but manipulating the RouteBinding object used to create the Route and ResourceAdapter

@yields [RouteBinding] temporary configuration object

# File lib/roadforest/application/dispatcher.rb, line 62
def add_route(name=nil, path_spec=nil, resource_type=nil, interface_class=nil)
  binder = Application::RouteBinding.new(self)

  binder.route_name = name
  binder.path_spec = path_spec
  binder.resource_type = resource_type
  binder.interface_class = interface_class

  yield binder if block_given?

  binder.validate!

  @route_names[name] = binder.route
  @routes << binder.route
  binder.route
end
Also aliased as: add
add_route_map(route_map) click to toggle source
# File lib/roadforest/application/dispatcher.rb, line 98
def add_route_map(route_map)
  @route_mappings << route_map
end
add_traced(name, path_spec, resource_type, interface_class, bindings = nil, &block)
Alias for: add_traced_route
add_traced_route(name, path_spec, resource_type, interface_class, bindings = nil) { |binder| ... } click to toggle source

@deprecated Just use add_route

# File lib/roadforest/application/dispatcher.rb, line 90
def add_traced_route(name, path_spec, resource_type, interface_class, bindings = nil, &block)
  add_route(name, path_spec, resource_type, interface_class) do |binder|
    binder.trace = true
    yield binder if block_given?
  end
end
Also aliased as: add_traced
add_untraced(name = nil, path_spec = nil, resource_type = nil, interface_class = nil)
Alias for: add_untraced_route
add_untraced_route(name = nil, path_spec = nil, resource_type = nil, interface_class = nil) { |binder| ... } click to toggle source

@deprecated Just use add_route

# File lib/roadforest/application/dispatcher.rb, line 81
def add_untraced_route(name = nil, path_spec = nil, resource_type = nil, interface_class = nil)
  add_route(name, path_spec, resource_type, interface_class) do |binder|
    binder.trace = false
    yield binder if block_given?
  end
end
Also aliased as: add_untraced
default_content_engine() click to toggle source
# File lib/roadforest/application/dispatcher.rb, line 49
def default_content_engine
  @services.default_content_engine
end
each_name_and_route(&block) click to toggle source
# File lib/roadforest/application/dispatcher.rb, line 45
def each_name_and_route(&block)
  @route_names.each_pair(&block)
end
each_route(&block) click to toggle source
# File lib/roadforest/application/dispatcher.rb, line 41
def each_route(&block)
  @routes.each(&block)
end
find_route(*args) { |route| ... } click to toggle source
Calls superclass method
# File lib/roadforest/application/dispatcher.rb, line 33
def find_route(*args)
  if block_given?
    @routes.find{|route| yield(route)}
  else
    super
  end
end
map_in(route_name) click to toggle source
# File lib/roadforest/application/dispatcher.rb, line 135
def map_in(route_name)
  RouteMap::Configurator.new(route_name, self)
end
mapped_route_for_name(from, name, params) click to toggle source
# File lib/roadforest/application/dispatcher.rb, line 21
def mapped_route_for_name(from, name, params)
  mapping = @route_mappings.find do |mapping|
    mapping.matches?(from, name, params)
  end

  unless mapping.nil?
    name = mapping.to_name
  end

  return route_for_name(name)
end
path_provider(route_name) click to toggle source
# File lib/roadforest/application/dispatcher.rb, line 53
def path_provider(route_name)
  PathProvider.new(route_name, self)
end
route_for_name(name) click to toggle source
# File lib/roadforest/application/dispatcher.rb, line 17
def route_for_name(name)
  @route_names.fetch(name)
end