Module: Excursion::Pool
- Defined in:
- lib/excursion/pool.rb,
lib/excursion/pool/application.rb,
lib/excursion/pool/dummy_application.rb
Defined Under Namespace
Classes: Application, DummyApplication
Constant Summary collapse
- @@applications =
{}
Class Method Summary collapse
- .application(name) ⇒ Object
- .datastore ⇒ Object
- .register_application(app) ⇒ Object
- .remove_application(app) ⇒ Object
Class Method Details
.application(name) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/excursion/pool.rb', line 9 def self.application(name) return @@applications[name] if @@applications.has_key?(name) app_yaml = datastore.get(name) @@applications[name] = Application.from_cache(app_yaml) unless app_yaml.nil? end |
.datastore ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/excursion/pool.rb', line 34 def self.datastore raise NoDatastoreError, "You must configure excursion with a datastore." if Excursion.configuration.datastore.nil? require "excursion/datastores/#{Excursion.configuration.datastore.to_s}" case Excursion.configuration.datastore.to_sym when :file raise DatastoreConfigurationError, "You must configure the :file datastore with a datastore_file path" if Excursion.configuration.datastore_file.nil? @@datastore ||= Excursion::Datastores::File.new(Excursion.configuration.datastore_file) when :memcache raise MemcacheConfigurationError, "You must configure the :memcache datastore with a memcache_server" if Excursion.configuration.memcache_server.nil? @@datastore ||= Excursion::Datastores::Memcache.new(Excursion.configuration.memcache_server) when :active_record raise TableDoesNotExist, "To use the :active_record datastore you must first run `rails generate excursion:active_record` followed by `rake db:migrate` to create the storage table" unless Excursion::RoutePool.table_exists? @@datastore ||= Excursion::Datastores::ActiveRecord.new when :active_record_with_memcache raise MemcacheConfigurationError, "You must configure the :active_record_with_memcache datastore with a memcache_server" if Excursion.configuration.memcache_server.nil? raise TableDoesNotExist, "To use the :active_record_with_memcache datastore you must first run `rails generate excursion:active_record` followed by `rake db:migrate` to create the storage table" unless Excursion::RoutePool.table_exists? @@datastore ||= Excursion::Datastores::ActiveRecord.new(Excursion.configuration.memcache_server) when :test @@datastore ||= Excursion::Datastores::Test.new end end |
.register_application(app) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/excursion/pool.rb', line 16 def self.register_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 config = {default_url_options: Excursion.configuration.} @@applications[name] = Application.new(name, config, app.routes.named_routes) datastore.set(name, @@applications[name].to_cache) end |
.remove_application(app) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/excursion/pool.rb', line 26 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 |