Class: Rsg::Generators::Orm::ActiveRecordGenerator
- Inherits:
-
Base
- Object
- Base
- Rsg::Generators::Orm::ActiveRecordGenerator
- Includes:
- Rails::Generators::Database
- Defined in:
- lib/rsg/generators/orm/active_record_generator.rb
Constant Summary collapse
- SUPPORTED_DBS =
%w(sqlite3 mysql postgres)
Class Method Summary collapse
Instance Method Summary collapse
- #banner ⇒ Object
- #configure_driver ⇒ Object
- #enable_active_record ⇒ Object
- #migrate ⇒ Object
- #write_db_sample ⇒ Object
Class Method Details
.source_paths ⇒ Object
12 13 14 15 16 17 |
# File 'lib/rsg/generators/orm/active_record_generator.rb', line 12 def self.source_paths @__source_paths ||= [ Rails::Generators::AppGenerator.source_root, Pathname.new(__FILE__).dirname.join("templates"). ] end |
.source_root ⇒ Object
8 9 10 |
# File 'lib/rsg/generators/orm/active_record_generator.rb', line 8 def self.source_root Pathname.new(__FILE__).dirname.join("templates"). end |
Instance Method Details
#banner ⇒ Object
19 20 21 |
# File 'lib/rsg/generators/orm/active_record_generator.rb', line 19 def say "Configuring active record" end |
#configure_driver ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/rsg/generators/orm/active_record_generator.rb', line 27 def configure_driver database ||= .fetch(:database) { ask("Which database you'd like to use?", limited_to: SUPPORTED_DBS, default: "sqlite3") } # From the core rails template template "config/databases/#{database}.yml", "config/database.yml" name, version = gem_for_database(database) append_gem name, version: version end |
#enable_active_record ⇒ Object
23 24 25 |
# File 'lib/rsg/generators/orm/active_record_generator.rb', line 23 def enable_active_record enable_railtie "active_record" end |
#migrate ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/rsg/generators/orm/active_record_generator.rb', line 42 def migrate if .key?(:auto_migrate) rake "db:create db:migrate" if [:auto_migrate] return end rake "db:create db:migrate" unless no?("Would you like to create the database schema?") end |
#write_db_sample ⇒ Object
36 37 38 39 40 |
# File 'lib/rsg/generators/orm/active_record_generator.rb', line 36 def write_db_sample copy_file "db.rake", "lib/tasks/db.rake" copy_file "seeds.rb", "db/seeds.rb" copy_file "samples.rb", "db/samples.rb" end |