class Excursion::Pool::Application

Attributes

default_url_options[RW]
name[RW]

Public Class Methods

from_cache(cached) click to toggle source
# File lib/excursion/pool/application.rb, line 6
def self.from_cache(cached)
  new(cached[:name], cached) unless cached.nil?
end
new(name, config, routes=nil) click to toggle source
# File lib/excursion/pool/application.rb, line 54
def initialize(name, config, routes=nil)
  @name = name
  from_cache(config)
  set_routes(routes) unless routes.nil?
end

Public Instance Methods

add_route(key, route) click to toggle source
# File lib/excursion/pool/application.rb, line 14
def add_route(key, route)
  route = journey_route(key, Rails.application, journey_path(route), {required_defaults: []}) unless route.is_a?(journey_route_class)
  routes.add(key.to_sym, route)
end
from_cache(cached) click to toggle source
# File lib/excursion/pool/application.rb, line 46
def from_cache(cached)
  @routes = routes_from_cache(cached[:routes]) if cached.has_key?(:routes)
  @default_url_options = cached[:default_url_options] || {}
  @registered_at = (Time.at(cached[:registered_at]) rescue Time.now)
end
route(key) click to toggle source
# File lib/excursion/pool/application.rb, line 10
def route(key)
  routes[key.to_sym]
end
routes() click to toggle source
# File lib/excursion/pool/application.rb, line 19
def routes
  @routes ||= ActionDispatch::Routing::RouteSet::NamedRouteCollection.new
end
routes=(routes) click to toggle source
# File lib/excursion/pool/application.rb, line 23
def routes=(routes)
  return @routes = routes if routes.is_a?(ActionDispatch::Routing::RouteSet::NamedRouteCollection)
  raise ArgumentError, 'routes must be a Hash or NamedRouteCollection' unless routes.is_a?(Hash)
  @routes = ActionDispatch::Routing::RouteSet::NamedRouteCollection.new
  routes.each do |name, route|
    route = journey_route(name, Rails.application, journey_path(route), {required_defaults: []}) unless route.is_a?(journey_route_class)
    @routes.add(name.to_sym, route)
  end
end
set_routes(routes) click to toggle source
# File lib/excursion/pool/application.rb, line 33
def set_routes(routes)
  self.routes = routes
end
to_cache() click to toggle source
# File lib/excursion/pool/application.rb, line 37
def to_cache
  {
    name: @name,
    routes: Hash[routes.map { |name, route| [name.to_sym, route.path.spec.to_s] }],
    default_url_options: @default_url_options,
    registered_at: @registered_at
  }
end

Protected Instance Methods

journey_path(path) click to toggle source
# File lib/excursion/pool/application.rb, line 80
def journey_path(path)
  journey_path_class.new(path)
end
journey_path_class() click to toggle source
# File lib/excursion/pool/application.rb, line 84
def journey_path_class
  if Excursion.rails3?
    Journey::Path::Pattern
  elsif Excursion.rails4?
    ActionDispatch::Journey::Path::Pattern
  end
end
journey_route(name, app, path, options) click to toggle source
# File lib/excursion/pool/application.rb, line 68
def journey_route(name, app, path, options)
  journey_route_class.new(name, app, path, options)
end
journey_route_class() click to toggle source
# File lib/excursion/pool/application.rb, line 72
def journey_route_class
  if Excursion.rails3?
    Journey::Route
  elsif Excursion.rails4?
    ActionDispatch::Journey::Route
  end
end
routes_from_cache(routes) click to toggle source
# File lib/excursion/pool/application.rb, line 60
def routes_from_cache(routes)
  collection = ActionDispatch::Routing::RouteSet::NamedRouteCollection.new
  routes.each do |name, path|
    collection.add(name.to_sym, journey_route(name, Rails.application, journey_path(path), {required_defaults: []}))
  end
  collection
end