Module: Duple::CLI::Helpers::InstanceMethods
- Defined in:
- lib/duple/cli/helpers.rb
Instance Method Summary collapse
- #app_config_path(verify_file = true) ⇒ Object
- #config ⇒ Object
- #data_file_path ⇒ Object
- #default_config_path ⇒ Object
- #dump_dir_path ⇒ Object
- #dump_flags ⇒ Object
- #heroku ⇒ Object
- #parse_config ⇒ Object
- #postgres ⇒ Object
- #reset_database(env) ⇒ Object
- #runner ⇒ Object
- #snapshot_file_path(timestamp) ⇒ Object
- #source ⇒ Object
- #source_db_config ⇒ Object
- #structure_file_path ⇒ Object
- #target ⇒ Object
- #target_appname ⇒ Object
- #target_db_config ⇒ Object
Instance Method Details
#app_config_path(verify_file = true) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/duple/cli/helpers.rb', line 84 def app_config_path(verify_file = true) config_path = [:config] || default_config_path if verify_file && !File.exists?(config_path) raise ArgumentError.new("Missing config file: #{config_path}") end config_path end |
#config ⇒ Object
72 73 74 |
# File 'lib/duple/cli/helpers.rb', line 72 def config @config ||= parse_config end |
#data_file_path ⇒ Object
128 129 130 131 |
# File 'lib/duple/cli/helpers.rb', line 128 def data_file_path # TODO: This should go on the configuration and be configurable. @data_file_path ||= File.join(dump_dir_path, "#{config.source_name}-data.dump") end |
#default_config_path ⇒ Object
92 93 94 |
# File 'lib/duple/cli/helpers.rb', line 92 def default_config_path File.join('config', 'duple.yml') end |
#dump_dir_path ⇒ Object
123 124 125 126 |
# File 'lib/duple/cli/helpers.rb', line 123 def dump_dir_path # TODO: This should go on the configuration and be configurable. File.join('tmp', 'duple') end |
#dump_flags ⇒ Object
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/duple/cli/helpers.rb', line 166 def dump_flags # TODO: This should be moved to the endpoint classes. include_tables = config.included_tables include_flags = include_tables.map { |t| "-t #{t}" } exclude_tables = config.excluded_tables exclude_flags = exclude_tables.map { |t| "-T #{t}" } flags = [ '-Fc -a', include_flags, exclude_flags ].flatten.compact.join(' ') end |
#heroku ⇒ Object
113 114 115 116 |
# File 'lib/duple/cli/helpers.rb', line 113 def heroku # TODO: This should go away as the methods are moved into the endpoint classes. @heroku ||= Duple::HerokuRunner.new(runner) end |
#parse_config ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/duple/cli/helpers.rb', line 76 def parse_config config_path = File.join(destination_root, app_config_path) config_data = File.read(config_path) erbed = ERB.new(config_data).result config_hash = YAML.load(erbed) || {} Duple::Configuration.new(config_hash, ) end |
#postgres ⇒ Object
108 109 110 111 |
# File 'lib/duple/cli/helpers.rb', line 108 def postgres # TODO: This should go away as the methods are moved into the endpoint classes. @pg_runner ||= Duple::PGRunner.new(runner) end |
#reset_database(env) ⇒ Object
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/duple/cli/helpers.rb', line 155 def reset_database(env) # TODO: This should be moved to the endpoint classes. if config.heroku?(env) appname = config.heroku_name(env) heroku.run(appname, 'pg:reset') else # if yes?("Are you sure you want to reset the #{config.target_name} database?", :red) runner.run('bundle exec rake db:drop db:create') end end |
#runner ⇒ Object
104 105 106 |
# File 'lib/duple/cli/helpers.rb', line 104 def runner @runner ||= Duple::Runner.new(dry_run: config.dry_run?) end |
#snapshot_file_path(timestamp) ⇒ Object
139 140 141 142 143 |
# File 'lib/duple/cli/helpers.rb', line 139 def snapshot_file_path() # TODO: This should go on the configuration and be configurable. filename = "#{config.source_name}-#{}.dump" @structure_file_path ||= File.join(dump_dir_path, filename) end |
#source ⇒ Object
96 97 98 |
# File 'lib/duple/cli/helpers.rb', line 96 def source @source ||= Duple::Source.new(config, runner) end |
#source_db_config ⇒ Object
145 146 147 148 |
# File 'lib/duple/cli/helpers.rb', line 145 def source_db_config # TODO: This should go away as the methods are moved into the endpoint classes. @source_db_config ||= source.db_config end |
#structure_file_path ⇒ Object
133 134 135 136 137 |
# File 'lib/duple/cli/helpers.rb', line 133 def structure_file_path # TODO: This should go on the configuration and be configurable. filename = "#{config.source_name}-structure.dump" @structure_file_path ||= File.join(dump_dir_path, filename) end |
#target ⇒ Object
100 101 102 |
# File 'lib/duple/cli/helpers.rb', line 100 def target @target ||= Duple::Target.new(config, runner) end |
#target_appname ⇒ Object
118 119 120 121 |
# File 'lib/duple/cli/helpers.rb', line 118 def target_appname # TODO: This should go away as the methods are moved into the endpoint classes. target.appname end |
#target_db_config ⇒ Object
150 151 152 153 |
# File 'lib/duple/cli/helpers.rb', line 150 def target_db_config # TODO: This should go away as the methods are moved into the endpoint classes. @target_db_config ||= target.db_config end |