Class: Squasher::Config
- Inherits:
-
Object
- Object
- Squasher::Config
- Defined in:
- lib/squasher/config.rb
Defined Under Namespace
Modules: Render
Instance Attribute Summary collapse
-
#migration_version ⇒ Object
readonly
Returns the value of attribute migration_version.
-
#schema_file ⇒ Object
readonly
Returns the value of attribute schema_file.
Instance Method Summary collapse
- #dbconfig? ⇒ Boolean
- #in_app_root(&block) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #migration_file(timestamp, migration_name) ⇒ Object
- #migration_files ⇒ Object
- #migrations_folder? ⇒ Boolean
- #set(key, value) ⇒ Object
- #set?(k) ⇒ Boolean
- #stub_dbconfig ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
39 40 41 42 43 44 45 |
# File 'lib/squasher/config.rb', line 39 def initialize @root_path = Dir.pwd.freeze @migrations_folder = File.join(@root_path, 'db', 'migrate') @flags = [] @databases = [] set_app_path(@root_path) end |
Instance Attribute Details
#migration_version ⇒ Object (readonly)
Returns the value of attribute migration_version.
37 38 39 |
# File 'lib/squasher/config.rb', line 37 def migration_version @migration_version end |
#schema_file ⇒ Object (readonly)
Returns the value of attribute schema_file.
37 38 39 |
# File 'lib/squasher/config.rb', line 37 def schema_file @schema_file end |
Instance Method Details
#dbconfig? ⇒ Boolean
88 89 90 |
# File 'lib/squasher/config.rb', line 88 def dbconfig? !dbconfig.nil? end |
#in_app_root(&block) ⇒ Object
112 113 114 |
# File 'lib/squasher/config.rb', line 112 def in_app_root(&block) Dir.chdir(@app_path, &block) end |
#migration_file(timestamp, migration_name) ⇒ Object
80 81 82 |
# File 'lib/squasher/config.rb', line 80 def migration_file(, migration_name) File.join(migrations_folder, "#{ }_#{ migration_name }.rb") end |
#migration_files ⇒ Object
76 77 78 |
# File 'lib/squasher/config.rb', line 76 def migration_files Dir.glob(File.join(migrations_folder, '**.rb')) end |
#migrations_folder? ⇒ Boolean
84 85 86 |
# File 'lib/squasher/config.rb', line 84 def migrations_folder? Dir.exist?(migrations_folder) end |
#set(key, value) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/squasher/config.rb', line 47 def set(key, value) if key == :engine base = value.nil? ? @root_path : File.(value, @root_path) list = Dir.glob(File.join(base, '**', '*', 'config', 'application.rb')) case list.size when 1 set_app_path(File.('../..', list.first)) when 0 Squasher.error(:cannot_find_dummy, base: base) else Squasher.error(:multi_dummy_case, base: base) end elsif key == :migration Squasher.error(:invalid_migration_version, value: value) unless value.to_s =~ /\A\d.\d\z/ @migration_version = "[#{value}]" elsif key == :sql @schema_file = File.join(@app_path, 'db', 'structure.sql') @flags << key elsif key == :databases @databases = value else @flags << key end end |
#set?(k) ⇒ Boolean
72 73 74 |
# File 'lib/squasher/config.rb', line 72 def set?(k) @flags.include?(k) end |
#stub_dbconfig ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/squasher/config.rb', line 92 def stub_dbconfig return unless dbconfig? list = [dbconfig_file, schema_file] list.each do |file| next unless File.exist?(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.exist?("#{ file }.sq") FileUtils.mv "#{ file }.sq", file end end |