Class: Arxutils_Sqlite3::Cli
- Inherits:
-
Object
- Object
- Arxutils_Sqlite3::Cli
- Defined in:
- lib/arxutils_sqlite3/cli.rb
Overview
CLI用クラス
Instance Method Summary collapse
- #acr ⇒ Object
- #clean ⇒ Object
- #copy_db_scheme ⇒ Object
- #copy_opts_file ⇒ Object
- #delete ⇒ Object
- #delete_db ⇒ Object
- #delete_migrate ⇒ Object
- #delete_nigrate ⇒ Object
- #delete_setting_yaml ⇒ Object
-
#initialize(config, dbconfig, env, acrecord, yaml_fname, _mod) ⇒ Cli
constructor
A new instance of Cli.
- #make_migrate_script ⇒ Object
- #makeconfig(opts) ⇒ Object
-
#migrate ⇒ Object
マイグレーション実行.
- #rm_dbconfig ⇒ Object
- #setup(mod) ⇒ Object
- #setup_for_migrate ⇒ Object
Constructor Details
#initialize(config, dbconfig, env, acrecord, yaml_fname, _mod) ⇒ Cli
Returns a new instance of Cli.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/arxutils_sqlite3/cli.rb', line 6 def initialize(config, dbconfig, env, acrecord, yaml_fname, _mod) @config = config @dbconfig = dbconfig @env = env @acrecord = acrecord @dbconfig_path = @config.make_dbconfig_path(@dbconfig) @db_scheme_ary = nil if yaml_fname && yaml_fname.strip != "" yaml_pn = Pathname.new(yaml_fname) @db_scheme_ary = YAML.load_file(yaml_pn) end @mig = @config.prepare_for_migrate(@db_scheme_ary, @dbconfig_path, @dbconfig, @acrecord) end |
Instance Method Details
#acr ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/arxutils_sqlite3/cli.rb', line 76 def acr # DB接続 connect_time = Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(@config, @dbconfig, @env) # `s` is a variable that is being used to store the value of the `gets` method. ret = :SUCCESS begin Dbsetup.new(connect_time) rescue StandardError => e puts e. ret = :StandardError end ret end |
#clean ⇒ Object
91 92 93 |
# File 'lib/arxutils_sqlite3/cli.rb', line 91 def clean @mig.delete_migrate_and_config_and_db end |
#copy_db_scheme ⇒ Object
33 34 35 36 |
# File 'lib/arxutils_sqlite3/cli.rb', line 33 def copy_db_scheme # DBスキームファイルが存在しなければ、サンプルファイルをDBスキームファイルとしてコピー @config.copy_db_scheme_file end |
#copy_opts_file ⇒ Object
38 39 40 41 |
# File 'lib/arxutils_sqlite3/cli.rb', line 38 def copy_opts_file # optsファイルが存在しなければ、サンプルファイルをoptsファイルとしてコピー @config.copy_opts_file end |
#delete ⇒ Object
95 96 97 |
# File 'lib/arxutils_sqlite3/cli.rb', line 95 def delete @mig.delete_migrate_and_db end |
#delete_db ⇒ Object
99 100 101 |
# File 'lib/arxutils_sqlite3/cli.rb', line 99 def delete_db @mig.delete_db end |
#delete_migrate ⇒ Object
111 112 113 |
# File 'lib/arxutils_sqlite3/cli.rb', line 111 def delete_migrate @mig.delete_migrate end |
#delete_nigrate ⇒ Object
103 104 105 |
# File 'lib/arxutils_sqlite3/cli.rb', line 103 def delete_nigrate @mig.delete_migrate end |
#delete_setting_yaml ⇒ Object
107 108 109 |
# File 'lib/arxutils_sqlite3/cli.rb', line 107 def delete_setting_yaml FileUtils.rm_f(@config.setting_yaml_file) end |
#make_migrate_script ⇒ Object
56 57 58 59 60 61 |
# File 'lib/arxutils_sqlite3/cli.rb', line 56 def make_migrate_script @dest_dbsetup_file = @config.dest_dbsetup_file @config.make_dbsetup_file(@db_scheme_ary, @acrecord, @mod, @dest_dbsetup_file) # マイグレーション用スクリプトの生成、acrecordのクラス定義ファイルの生成 @mig.output end |
#makeconfig(opts) ⇒ Object
52 53 54 |
# File 'lib/arxutils_sqlite3/cli.rb', line 52 def makeconfig(opts) @mig.make_dbconfig(opts) end |
#migrate ⇒ Object
マイグレーション実行
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/arxutils_sqlite3/cli.rb', line 64 def migrate # migrate用スクリプトの出力先ディレクトリ名 migrate_dir = @config.migrate_dir # DB接続 Arxutils_Sqlite3::Dbutil::Dbconnect.db_connect(@config, @dbconfig, @env) # マイグレーション実行 # ActiveRecord::MigrationContext.new(migrate_dir, ActiveRecord::SchemaMigration).up ActiveRecord::MigrationContext.new(migrate_dir).up end |
#rm_dbconfig ⇒ Object
115 116 117 118 119 |
# File 'lib/arxutils_sqlite3/cli.rb', line 115 def rm_dbconfig dbconfig_path = @config.make_dbconfig_path(@dbconfig) # p dbconfig_path FileUtils.rm_f(dbconfig_path) end |
#setup(mod) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/arxutils_sqlite3/cli.rb', line 21 def setup(mod) # p "make_config_directory" @config.make_config_directory # p "setup_db_scheme_file" @config.setup_db_scheme_file(mod) # p "setup_opts_file(#{mod})" @config.setup_opts_file(mod) # p "setup_setting_yaml_file(#{mod})" @config.setup_setting_yaml_file(mod) # db_scheme_ary = nil end |
#setup_for_migrate ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/arxutils_sqlite3/cli.rb', line 43 def setup_for_migrate ret = :SUCCESS db_scheme_ary = nil dbconfig_path = @config.make_dbconfig_path(@dbconfig) # @config.check_file_exist(dbconfig_path, banner, exit_code) @config.prepare_for_migrate(db_scheme_ary, dbconfig_path, @dbconfig, @acrecord) ret end |