Created
July 27, 2011 00:15
-
-
Save masaki/1108410 to your computer and use it in GitHub Desktop.
create Rails config files as Rake task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- 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