Class: MultipleDbsInitializerGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- MultipleDbsInitializerGenerator
- Defined in:
- lib/generators/multiple_dbs_initializer/multiple_dbs_initializer_generator.rb
Constant Summary collapse
- @@default_db_config =
@@default_db_config
default database configuration { "adapter"=> "postgresql", "encoding"=> "unicode", "pool"=> 5, "username"=> "root", "password"=> "toor", }
Instance Method Summary collapse
-
#databases ⇒ Object
databases = [:db1, :db2] an array that stores the databases names.
-
#define_multiple_dbs_constant ⇒ Object
define_multiple_dbs_constant Create the multiple_dbs_initializer.rb file.
-
#development ⇒ Object
development = @@default_db_config a hash that allows the user to change the default database configuration for the development environment through the options.
-
#not_override ⇒ Object
not_override If false override the config/database.yml otherwise not override it.
-
#production ⇒ Object
production = @@default_db_config a hash that allows the user to change the default database configuration for the production environment through the options.
-
#test ⇒ Object
test = @@default_db_config a hash that allows the user to change the default database configuration for the test environment through the options.
Instance Method Details
#databases ⇒ Object
databases = [:db1, :db2] an array that stores the databases names.
16 |
# File 'lib/generators/multiple_dbs_initializer/multiple_dbs_initializer_generator.rb', line 16 argument :databases, type: :array, default: [:db1, :db2] |
#define_multiple_dbs_constant ⇒ Object
define_multiple_dbs_constant
Create the multiple_dbs_initializer.rb file.
This file define the MultipleDbs::DBS constant
and the MultipleDbs::DbConnection per database.
Also delete the config/multiple_dbs folder and
create the ymls files that store the database
configuration
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/generators/multiple_dbs_initializer/multiple_dbs_initializer_generator.rb', line 42 def define_multiple_dbs_constant copy_file "initializer.rb", "config/initializers/multiple_dbs_initializer.rb" insert_into_file "config/initializers/multiple_dbs_initializer.rb", %Q{\tDBS=#{databases.map{|db| db.to_s.underscore.to_sym}} run_setup\n}, after: "# Your databases.\n", verbose: false remove_file "config/multiple_dbs", verbose: false inject_into_class "app/controllers/application_controller.rb", ApplicationController, %Q{\t\t# def mdb_name # Thread.current[:mdb_name] ||= ... somthing that gives you the database name, like: 'db1' or 'client1_database' # end # before_filter do # MultipleDbs.validate_connection(mdb_name) # end\n} databases.each do |db| create_database_config_file db end create_database_config_file if !.not_override end |
#development ⇒ Object
development = @@default_db_config
a hash that allows the user to change the default database configuration
for the development environment through the
21 |
# File 'lib/generators/multiple_dbs_initializer/multiple_dbs_initializer_generator.rb', line 21 class_option :development, type: :hash, default: @@default_db_config |
#not_override ⇒ Object
not_override If false override the config/database.yml otherwise not override it
33 |
# File 'lib/generators/multiple_dbs_initializer/multiple_dbs_initializer_generator.rb', line 33 class_option :not_override, type: :boolean, default: true |
#production ⇒ Object
production = @@default_db_config
a hash that allows the user to change the default database configuration
for the production environment through the
25 |
# File 'lib/generators/multiple_dbs_initializer/multiple_dbs_initializer_generator.rb', line 25 class_option :production, type: :hash, default: @@default_db_config |
#test ⇒ Object
test = @@default_db_config
a hash that allows the user to change the default database configuration
for the test environment through the
29 |
# File 'lib/generators/multiple_dbs_initializer/multiple_dbs_initializer_generator.rb', line 29 class_option :test, type: :hash, default: @@default_db_config |