Module: Contineo
- Defined in:
- lib/contineo.rb,
lib/contineo/version.rb
Defined Under Namespace
Modules: VERSION
Class Method Summary collapse
- .configurations ⇒ Object
- .create_connections ⇒ Object
- .db(db_env) ⇒ Object
- .define_db_connection_class(db_env) ⇒ Object
- .env(db_env) ⇒ Object
- .other_than_application_db?(db_env) ⇒ Boolean
-
.version ⇒ Object
Returns the version of the currently loaded Contineo as a Gem::Version.
Class Method Details
.configurations ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/contineo.rb', line 30 def self.configurations begin YAML.load_file(CONFIG_PATH) rescue NameError => e YAML.load_file("config/database.yml") end end |
.create_connections ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/contineo.rb', line 38 def self.create_connections configurations.each do |db_env, connection_hash| if other_than_application_db?(db_env) && ::Rails.env == env(db_env) define_db_connection_class(db_env) end end end |
.db(db_env) ⇒ Object
6 7 8 |
# File 'lib/contineo.rb', line 6 def self.db(db_env) db_env.split('_'+ env(db_env)).first.camelcase end |
.define_db_connection_class(db_env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/contineo.rb', line 18 def self.define_db_connection_class(db_env) klass = Object.const_set(db(db_env), Class.new(ActiveRecord::Base) { self.abstract_class = true def self.inherited(base) contineo end }) klass.define_singleton_method(:contineo) { establish_connection db_env.to_sym } klass end |
.env(db_env) ⇒ Object
10 11 12 |
# File 'lib/contineo.rb', line 10 def self.env(db_env) db_env.split('_').last end |
.other_than_application_db?(db_env) ⇒ Boolean
14 15 16 |
# File 'lib/contineo.rb', line 14 def self.other_than_application_db?(db_env) db_env.split('_').size > 1 end |
.version ⇒ Object
Returns the version of the currently loaded Contineo as a Gem::Version
3 4 5 |
# File 'lib/contineo/version.rb', line 3 def self.version Gem::Version.new "0.1.3" end |