Class: Squasher::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/squasher/config.rb

Instance Method Summary collapse

Constructor Details

#initializeConfig

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

Returns:

  • (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(timestamp, migration_name)
  File.join(migrations_folder, "#{ timestamp }_#{ migration_name }.rb")
end

#migration_filesObject



15
16
17
# File 'lib/squasher/config.rb', line 15

def migration_files
  Dir.glob(File.join(migrations_folder, '**.rb'))
end

#migrations_folder?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/squasher/config.rb', line 23

def migrations_folder?
  Dir.exists?(migrations_folder)
end

#schema_fileObject



11
12
13
# File 'lib/squasher/config.rb', line 11

def schema_file
  @schema_file ||= from_root('db', 'schema.rb')
end

#stub_dbconfigObject



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