Class: Excursion::Pool::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/excursion/pool/application.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_url_optionsObject (readonly)

Returns the value of attribute default_url_options.



4
5
6
# File 'lib/excursion/pool/application.rb', line 4

def default_url_options
  @default_url_options
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/excursion/pool/application.rb', line 4

def name
  @name
end

Class Method Details

.from_cache(cached) ⇒ Object



6
7
8
# File 'lib/excursion/pool/application.rb', line 6

def self.from_cache(cached)
  new.from_cache(cached)
end

Instance Method Details

#from_cache(cached = {}) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/excursion/pool/application.rb', line 46

def from_cache(cached={})
  @name = cached[:name] # required
  @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)
  self
end

#route(key) ⇒ Object



10
11
12
# File 'lib/excursion/pool/application.rb', line 10

def route(key)
  routes[key.to_sym]
end

#routesObject



14
15
16
# File 'lib/excursion/pool/application.rb', line 14

def routes
  @routes ||= ActionDispatch::Routing::RouteSet::NamedRouteCollection.new
end

#routes=(routes) ⇒ Object



18
19
20
21
22
23
# File 'lib/excursion/pool/application.rb', line 18

def routes=(routes)
  @routes = ActionDispatch::Routing::RouteSet::NamedRouteCollection.new
  routes.each do |name, route|
    @routes.add(name, route)
  end
end

#routes_from_cache(routes) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/excursion/pool/application.rb', line 38

def routes_from_cache(routes)
  collection = ActionDispatch::Routing::RouteSet::NamedRouteCollection.new
  routes.each do |name, path|
    collection.add(name, ActionDispatch::Journey::Route.new(name, Rails.application, ActionDispatch::Journey::Path::Pattern.new(path), {required_defaults: []}))
  end
  collection
end

#set_routes(routes) ⇒ Object



25
26
27
28
# File 'lib/excursion/pool/application.rb', line 25

def set_routes(routes)
  self.routes = routes
  self
end

#to_cacheObject



30
31
32
33
34
35
36
# File 'lib/excursion/pool/application.rb', line 30

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