Class: Squasher::Config
- Inherits:
-
Object
- Object
- Squasher::Config
- Defined in:
- lib/squasher/config.rb
Instance Method Summary collapse
- #dbconfig? ⇒ Boolean
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #migration_file(timestamp, migration_name) ⇒ Object
- #migration_files ⇒ Object
- #migrations_folder? ⇒ Boolean
- #schema_file ⇒ Object
- #stub_dbconfig ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
7 8 9 |
# File 'lib/squasher/config.rb', line 7 def initialize @root_path = Dir.pwd end |
Instance Method Details
#dbconfig? ⇒ Boolean
27 28 29 |
# File 'lib/squasher/config.rb', line 27 def dbconfig? !dbconfig.nil? end |
#migration_file(timestamp, migration_name) ⇒ Object
19 20 21 |
# File 'lib/squasher/config.rb', line 19 def migration_file(, migration_name) File.join(migrations_folder, "#{ }_#{ migration_name }.rb") end |
#migration_files ⇒ Object
15 16 17 |
# File 'lib/squasher/config.rb', line 15 def migration_files Dir.glob(File.join(migrations_folder, '**.rb')) end |
#migrations_folder? ⇒ Boolean
23 24 25 |
# File 'lib/squasher/config.rb', line 23 def migrations_folder? Dir.exists?(migrations_folder) end |
#schema_file ⇒ Object
11 12 13 |
# File 'lib/squasher/config.rb', line 11 def schema_file @schema_file ||= from_root('db', 'schema.rb') end |
#stub_dbconfig ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/squasher/config.rb', line 31 def stub_dbconfig return unless dbconfig? list = [dbconfig_file, schema_file] list.each do |file| next unless File.exists?(file) FileUtils.mv file, "#{ file }.sbackup" end update_dbconfig_file yield ensure list.each do |file| next unless File.exists?("#{ file }.sbackup") FileUtils.mv "#{ file }.sbackup", file end end |