Top Level Namespace
Defined Under Namespace
Modules: Que Classes: DesmondConfig
Constant Summary collapse
- CENSORED_KEYS =
configure log censoring, so that password and AWS secret keys don’t end up in the logs
%w(password secret_access_key)
Instance Method Summary collapse
-
#copy_migration(source_file, dest_folder) ⇒ Object
copy migration
source_file
to migrations folderdest_folder
if it doesn’t exist ther yet. -
#migrations(dirname) ⇒ Object
returns migration files in the given directory
dirname
. -
#next_migration_number(dirname) ⇒ Object
returns the next migration number to use from the given directory
dirname
.
Instance Method Details
#copy_migration(source_file, dest_folder) ⇒ Object
copy migration source_file
to migrations folder dest_folder
if it doesn’t exist ther yet
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/desmond/rake.rb', line 36 def copy_migration(source_file, dest_folder) # check if migration already exists migration_exists = migrations(dest_folder).map do |file| File.basename(file).split('_')[1..-1].join('_').eql?(File.basename(source_file)) end.any? return if migration_exists # copy migration file migration_number = next_migration_number(dest_folder) base_migration_name = File.basename source_file migration_name = "#{migration_number}_#{base_migration_name}" dest_file = File.join dest_folder, migration_name FileUtils.cp(source_file, dest_file) end |
#migrations(dirname) ⇒ Object
returns migration files in the given directory dirname
7 8 9 10 11 |
# File 'lib/desmond/rake.rb', line 7 def migrations(dirname) Dir.foreach(dirname).select do |entry| !entry.start_with?('.') end end |
#next_migration_number(dirname) ⇒ Object
returns the next migration number to use from the given directory dirname
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/desmond/rake.rb', line 16 def next_migration_number(dirname) current_migration_number_str = migrations(dirname).map do |file| File.basename(file).split('_').first end.max || '0000' current_migration_number = current_migration_number_str.to_i num_digits = current_migration_number_str.size if num_digits > 5 # timestamp format [Time.now.utc.strftime('%Y%m%d%H%M%S'), format('%.14d', current_migration_number + 1)].max else # counter format format("%.#{num_digits}d", current_migration_number + 1) end end |