Class: Squasher::Config
- Inherits:
-
Object
- Object
- Squasher::Config
- Defined in:
- lib/squasher/config.rb
Instance Attribute Summary collapse
-
#schema_file ⇒ Object
readonly
Returns the value of attribute schema_file.
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
- #stub_dbconfig ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
9 10 11 12 13 14 15 |
# File 'lib/squasher/config.rb', line 9 def initialize root_path = Dir.pwd @schema_file = File.join(root_path, 'db', 'schema.rb') @migrations_folder = File.join(root_path, 'db', 'migrate') @dbconfig_file = File.join(root_path, 'config', 'database.yml') end |
Instance Attribute Details
#schema_file ⇒ Object (readonly)
Returns the value of attribute schema_file.
7 8 9 |
# File 'lib/squasher/config.rb', line 7 def schema_file @schema_file end |
Instance Method Details
#dbconfig? ⇒ Boolean
29 30 31 |
# File 'lib/squasher/config.rb', line 29 def dbconfig? !dbconfig.nil? end |
#migration_file(timestamp, migration_name) ⇒ Object
21 22 23 |
# File 'lib/squasher/config.rb', line 21 def migration_file(, migration_name) File.join(migrations_folder, "#{ timestamp }_#{ migration_name }.rb") end |
#migration_files ⇒ Object
17 18 19 |
# File 'lib/squasher/config.rb', line 17 def migration_files Dir.glob(File.join(migrations_folder, '**.rb')) end |
#migrations_folder? ⇒ Boolean
25 26 27 |
# File 'lib/squasher/config.rb', line 25 def migrations_folder? Dir.exists?(migrations_folder) end |
#stub_dbconfig ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/squasher/config.rb', line 33 def stub_dbconfig return unless dbconfig? list = [dbconfig_file, schema_file] list.each do |file| next unless File.exists?(file) FileUtils.mv file, "#{ file }.sq" end File.open(dbconfig_file, 'wb') { |stream| stream.write dbconfig.to_yaml } yield ensure list.each do |file| next unless File.exists?("#{ file }.sq") FileUtils.mv "#{ file }.sq", file end end |