forked from fixin.me/fixin.me
Rake task to export default settings as seeds
This commit is contained in:
14
lib/core_ext/big_decimal/formatting.rb
Normal file
14
lib/core_ext/big_decimal/formatting.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
module FixinMe
|
||||
module BigDecimalScientificNotation
|
||||
def to_scientific
|
||||
return 'NaN' unless finite?
|
||||
|
||||
sign, coefficient, base, exponent = split
|
||||
(sign == -1 ? '-' : '') +
|
||||
(coefficient.length > 1 ? coefficient.insert(1, '.') : coefficient) +
|
||||
(exponent != 1 ? "e#{exponent-1}" : '')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
BigDecimal.prepend(FixinMe::BigDecimalScientificNotation)
|
||||
12
lib/tasks/db.rake
Normal file
12
lib/tasks/db.rake
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace :db do
|
||||
namespace :seed do
|
||||
desc "Dump default settings as seed data to db/seeds/*.rb"
|
||||
task export: :environment do
|
||||
seeds_path = Pathname.new(Rails.application.paths["db"].first) / 'seeds'
|
||||
(seeds_path / 'templates').glob('*.erb').each do |template_path|
|
||||
template = ERB.new(template_path.read, trim_mode: '<>')
|
||||
(seeds_path / "#{template_path.basename('.*').to_s}.rb").write(template.result)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user