Skip to content

Instantly share code, notes, and snippets.

@masaki
Created July 27, 2011 00:15
Show Gist options
  • Save masaki/1108410 to your computer and use it in GitHub Desktop.
Save masaki/1108410 to your computer and use it in GitHub Desktop.
create Rails config files as Rake task
# -*- encoding: utf-8 -*-
namespace :setup do
def copy_config(options = {})
Dir["#{RAILS_ROOT}/**/*.sample", "#{RAILS_ROOT}/**/*.example"].each do |source|
target = source.sub(/\.(ex|s)ample$/, '')
if options[:force] or not File.exist?(target)
require 'fileutils'
puts "Create config file '#{target}' from '#{source}'"
FileUtils.copy_file source, target
end
end
end
def copy_config!
copy_config(:force => true)
end
desc "Create config file from *.sample or *.example"
task :config do |t|
copy_config
end
namespace :config do
desc "Create config file forcibly from *.sample or *.example"
task :force do |t|
copy_config!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment