diff --git a/.gitignore b/.gitignore index b388b57..025d19c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ pkg/* Manifest *.gemspec tmp/* +.bundle/* diff --git a/Gemfile b/Gemfile index dd9563d..ad339a8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,9 @@ gem 'rainbow' - -group :test do - gem 'rspec' - gem 'autotest' - gem 'mocha' -end +gem 'echoe' +gem 'rspec' +gem 'autotest' +gem 'mocha' +gem 'reek' +gem 'sdoc' +gem 'sdoc-helpers', :require => 'sdoc_helpers' +gem 'rdiscount' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..0cb9a6e --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,57 @@ +GEM + specs: + autotest (4.4.1) + diff-lcs (1.1.2) + echoe (4.3.1) + gemcutter + rubyforge + gemcutter (0.6.1) + json (1.4.6) + json_pure (1.4.3) + mocha (0.9.8) + rake + rainbow (1.1) + rake (0.8.7) + rdiscount (1.6.5) + rdoc (2.4.3) + reek (1.2.8) + ruby2ruby (~> 1.2) + ruby_parser (~> 2.0) + sexp_processor (~> 3.0) + rspec (2.0.1) + rspec-core (~> 2.0.1) + rspec-expectations (~> 2.0.1) + rspec-mocks (~> 2.0.1) + rspec-core (2.0.1) + rspec-expectations (2.0.1) + diff-lcs (>= 1.1.2) + rspec-mocks (2.0.1) + rspec-core (~> 2.0.1) + rspec-expectations (~> 2.0.1) + ruby2ruby (1.2.4) + ruby_parser (~> 2.0) + sexp_processor (~> 3.0) + ruby_parser (2.0.4) + sexp_processor (~> 3.0) + rubyforge (2.0.4) + json_pure (>= 1.1.7) + sdoc (0.2.20) + json (>= 1.1.3) + rdoc (= 2.4.3) + sdoc-helpers (0.1.4) + sdoc (~> 0.2) + sexp_processor (3.0.4) + +PLATFORMS + ruby + +DEPENDENCIES + autotest + echoe + mocha + rainbow + rdiscount + reek + rspec + sdoc + sdoc-helpers diff --git a/Rakefile b/Rakefile index 9099ac1..95869e8 100644 --- a/Rakefile +++ b/Rakefile @@ -1,13 +1,15 @@ +require 'rubygems' +require 'bundler' + +Bundler.require(:default) + $LOAD_PATH << 'lib' -require 'rubygems' require 'yaml' require 'apache' -require 'spec/rake/spectask' -require 'sdoc' +require 'rspec/core/rake_task' require 'sdoc_helpers/markdown' -require 'echoe' namespace :apache do desc "Generate the configs" @@ -28,11 +30,11 @@ end namespace :spec do desc "Run RCov tests" - Spec::Rake::SpecTask.new('rcov') do |t| - t.spec_files = FileList['spec/*.rb'] + RSpec::Core::RakeTask.new(:rcov) do |t| + t.pattern = 'spec/*.rb' t.rcov = true t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems'] - t.spec_opts = ['-b'] + t.rspec_opts = ['-b'] end end diff --git a/lib/apache/config.rb b/lib/apache/config.rb index 8b406ce..658bb3a 100644 --- a/lib/apache/config.rb +++ b/lib/apache/config.rb @@ -4,6 +4,7 @@ require 'bundler' Bundler.require(:default) require 'fileutils' +require 'rainbow' Dir[File.join(File.dirname(__FILE__), '*.rb')].each { |f| require f } diff --git a/lib/apache/rake/create.rb b/lib/apache/rake/create.rb index 00715ba..df5b567 100644 --- a/lib/apache/rake/create.rb +++ b/lib/apache/rake/create.rb @@ -1,8 +1,9 @@ +Bundler.require(:default) + require 'fileutils' require 'yaml' require 'apache/config' require 'apache/rake/create' -require 'rainbow' CONFIG = Hash[YAML.load_file('config.yml').collect { |k,v| [ k.to_sym, v ] }] @@ -14,17 +15,29 @@ def get_environments }.flatten.uniq.sort.collect { |name| name[1..-1] } end +def get_default_environment + File.read('.environment').strip rescue nil +end + +def need_environment + puts "You need to specify an environment. Available environments:" + puts + puts get_environments.collect { |env| "rake apache:create[#{env}]" } * "\n" + puts + puts "Additionally, you can set a default environment for this server:" + puts + puts "rake apache:default[#{get_environments.first}]" + exit 1 +end + +task :default => 'apache:create' + namespace :apache do desc "Create all defined configs for the specified environment" task :create, :environment do |t, args| - if !args[:environment] - puts "You need to specify an environment. Available environments:" - puts - puts get_environments.collect { |env| "rake apache:create[#{env}]" } * "\n" - exit 1 - end + need_environment if !args[:environment] && !get_default_environment - APACHE_ENV = (args[:environment] || 'production').to_sym + APACHE_ENV = (args[:environment] || get_default_environment).to_sym CONFIG[:source_path] = File.expand_path(CONFIG[:source]) CONFIG[:dest_path] = File.expand_path(CONFIG[:destination]) @@ -44,4 +57,17 @@ namespace :apache do task :environments do puts get_environments * "\n" end + + desc "Set the default environment (currently #{get_default_environment || 'nil'})" + task :default, :environment do |t, args| + need_environment if !args[:environment] + + if get_environments.include?(args[:environment]) + File.open('.environment', 'w') { |fh| fh.puts args[:environment] } + puts "Calls to apache:create will now use #{args[:environment]} when you don't specify the environment." + else + puts "You need to specify a valid default environment. Here are the possibilities:" + Rake::Task['apache:environments'].invoke + end + end end