Class: Excursion::Pool::Application
- Inherits:
-
Object
- Object
- Excursion::Pool::Application
- Defined in:
- lib/excursion/pool/application.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#default_url_options ⇒ Object
Returns the value of attribute default_url_options.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #add_route(key, route) ⇒ Object
- #from_cache(cached) ⇒ Object
- #route(key) ⇒ Object
- #routes ⇒ Object
- #routes=(routes) ⇒ Object
- #set_routes(routes) ⇒ Object
- #to_cache ⇒ Object
Instance Attribute Details
#default_url_options ⇒ Object
Returns the value of attribute default_url_options.
4 5 6 |
# File 'lib/excursion/pool/application.rb', line 4 def @default_url_options end |
#name ⇒ Object
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(cached[:name], cached) unless cached.nil? end |
Instance Method Details
#add_route(key, route) ⇒ Object
14 15 16 17 |
# 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) ⇒ Object
46 47 48 49 50 |
# 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) ⇒ Object
10 11 12 |
# File 'lib/excursion/pool/application.rb', line 10 def route(key) routes[key.to_sym] end |
#routes ⇒ Object
19 20 21 |
# File 'lib/excursion/pool/application.rb', line 19 def routes @routes ||= ActionDispatch::Routing::RouteSet::NamedRouteCollection.new end |
#routes=(routes) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# 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) ⇒ Object
33 34 35 |
# File 'lib/excursion/pool/application.rb', line 33 def set_routes(routes) self.routes = routes end |
#to_cache ⇒ Object
37 38 39 40 41 42 43 44 |
# 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 |