Class: PhobosDBCheckpoint::CLI::Commands
- Inherits:
-
Thor
- Object
- Thor
- PhobosDBCheckpoint::CLI::Commands
- Includes:
- Thor::Actions
- Defined in:
- lib/phobos_db_checkpoint/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #copy_migrations ⇒ Object
- #init ⇒ Object
- #init_events_api ⇒ Object
- #migration(name) ⇒ Object
- #version ⇒ Object
Class Method Details
.source_root ⇒ Object
87 88 89 |
# File 'lib/phobos_db_checkpoint/cli.rb', line 87 def self.source_root File.(File.join(File.dirname(__FILE__), '../..')) end |
Instance Method Details
#copy_migrations ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/phobos_db_checkpoint/cli.rb', line 41 def copy_migrations if [:config] ENV['DB_CONFIG'] = [:config] end unless active_connection? PhobosDBCheckpoint.configure end destination_fullpath = File.join(destination_root, [:destination]) generated_migrations = list_migrations(destination_fullpath) FileUtils.mkdir_p(destination_fullpath) file_path = nil .each do || if migration_exists?(generated_migrations, [:name]) say_status('exists', [:name]) else file_path = File.join([:destination], "#{[:number]}_#{[:name]}") template_path = File.join('templates/migrate', [:path]) template(template_path, file_path) end end rescue FileUtils.rm_f(file_path.to_s) raise end |
#init ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/phobos_db_checkpoint/cli.rb', line 19 def init create_file('Rakefile') unless File.exist?(File.join(destination_root, 'Rakefile')) prepend_to_file 'Rakefile', "require 'phobos_db_checkpoint'\nPhobosDBCheckpoint.load_tasks\n" copy_file 'templates/database.yml.example', 'config/database.yml' cmd = self.class.new cmd.destination_root = destination_root cmd.invoke(:copy_migrations) create_file('phobos_boot.rb') unless File.exist?(File.join(destination_root, 'phobos_boot.rb')) append_to_file 'phobos_boot.rb', File.read(phobos_boot_template) end |
#init_events_api ⇒ Object
82 83 84 85 |
# File 'lib/phobos_db_checkpoint/cli.rb', line 82 def init_events_api copy_file 'templates/config.ru', 'config.ru' say ' Start the API with: `rackup config.ru`' end |
#migration(name) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/phobos_db_checkpoint/cli.rb', line 73 def migration(name) migration_name = name.gsub(/[^\w]*/, '') @new_migration_class_name = migration_name.split('_').map(&:capitalize).join('') file_name = "#{migration_number}_#{migration_name}.rb" destination_fullpath = File.join(destination_root, [:destination], file_name) template(new_migration_template, destination_fullpath) end |
#version ⇒ Object
14 15 16 |
# File 'lib/phobos_db_checkpoint/cli.rb', line 14 def version puts PhobosDBCheckpoint::VERSION end |