Module: Excursion::Pool
- Defined in:
- lib/excursion/pool.rb,
lib/excursion/pool/dsl.rb,
lib/excursion/pool/application.rb,
lib/excursion/pool/dummy_application.rb
Defined Under Namespace
Classes: Application, DSL, DummyApplication
Constant Summary
collapse
- @@applications =
{}
Class Method Summary
collapse
Class Method Details
.all_applications ⇒ Object
10
11
12
13
14
15
|
# File 'lib/excursion/pool.rb', line 10
def self.all_applications
datastore.all_apps.each do |app|
@@applications[app.name] = app
end
@@applications
end
|
.application(name) ⇒ Object
17
18
19
20
21
22
|
# File 'lib/excursion/pool.rb', line 17
def self.application(name)
return @@applications[name] if @@applications.has_key?(name) && !@@applications[name].nil?
app = datastore.app(name)
@@applications[name] = app unless app.nil?
end
|
.register_application(app = nil, opts = {}, &block) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/excursion/pool.rb', line 24
def self.register_application(app=nil, opts={}, &block)
raise ArgumentError, "app must be an instance of Rails::Application" unless app.is_a?(Rails::Application) || block_given?
opts = {store: true}.merge(opts)
if app.is_a?(Rails::Application)
name = app.class.name.underscore.split("/").first
config = {default_url_options: Excursion.configuration.default_url_options}
routes = app.routes.named_routes
@@applications[name] = Application.new(name, config, routes)
end
if block_given?
if @@applications.has_key?(name)
DSL.block_eval(@@applications[name], &block)
else
block_app = DSL.block_eval(&block)
name = block_app.name
@@applications[name] = block_app
end
end
datastore.set(name, @@applications[name].to_cache) if opts[:store]
@@applications[name]
end
|
.register_hash(app_hash) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/excursion/pool.rb', line 49
def self.register_hash(app_hash)
raise ArgumentError, "you must provide at minimum a hash with a :name key" unless app_hash.is_a?(Hash) && app_hash.has_key?(:name)
app_hash = {default_url_options: Excursion.configuration.default_url_options, routes: {}, registered_at: Time.now}.merge(app_hash)
name = app_hash[:name]
datastore.set(name, app_hash)
@@applications[name] = datastore.app(name)
end
|
.remove_application(app) ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/excursion/pool.rb', line 59
def self.remove_application(app)
raise ArgumentError, "app must be an instance of Rails::Application" unless app.is_a?(Rails::Application)
name = app.class.name.underscore.split("/").first
datastore.delete(name)
@@applications.delete(name)
end
|