From 760d36766bb143820bd593cfceb951fed6312cc0 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 27 Sep 2011 15:30:38 -0400 Subject: [PATCH] rearrange some things to make it more modern --- Gemfile.lock | 32 +++++---- Guardfile | 9 +++ apache-config-generator.gemspec | 5 +- lib/apache.rb | 24 ++++++- lib/apache/apachify.rb | 118 ------------------------------- lib/apache/config.rb | 4 -- lib/apache/core_ext/array.rb | 40 +++++++++++ lib/apache/core_ext/fixnum.rb | 4 ++ lib/apache/core_ext/hash.rb | 28 ++++++++ lib/apache/core_ext/string.rb | 28 ++++++++ lib/apache/core_ext/symbol.rb | 24 +++++++ lib/apache/hash.rb | 8 --- lib/apache/rake/apache/create.rb | 3 +- lib/apache/rake/support.rb | 1 - lib/apache/rewrites.rb | 2 - spec/apache/apachify_spec.rb | 1 - spec/apache/config_spec.rb | 2 +- spec/apache/directory_spec.rb | 2 +- spec/apache/hash_spec.rb | 1 - spec/apache/logging_spec.rb | 1 - spec/apache/rake/support_spec.rb | 3 +- spec/spec_helper.rb | 4 +- tools.watchr | 22 ------ 23 files changed, 183 insertions(+), 183 deletions(-) create mode 100644 Guardfile create mode 100644 lib/apache/core_ext/array.rb create mode 100644 lib/apache/core_ext/fixnum.rb create mode 100644 lib/apache/core_ext/hash.rb create mode 100644 lib/apache/core_ext/string.rb create mode 100644 lib/apache/core_ext/symbol.rb delete mode 100644 lib/apache/hash.rb delete mode 100644 tools.watchr diff --git a/Gemfile.lock b/Gemfile.lock index b8a62fc..7a90983 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,8 +7,11 @@ PATH GEM remote: http://rubygems.org/ specs: - autotest (4.4.2) - diff-lcs (1.1.2) + diff-lcs (1.1.3) + guard (0.7.0) + thor (~> 0.14.6) + guard-rspec (0.4.5) + guard (>= 0.4.0) mocha (0.9.10) rake nokogiri (1.4.3.1) @@ -18,32 +21,31 @@ GEM 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) + rspec (2.6.0) + rspec-core (~> 2.6.0) + rspec-expectations (~> 2.6.0) + rspec-mocks (~> 2.6.0) + rspec-core (2.6.4) + rspec-expectations (2.6.0) + diff-lcs (~> 1.1.2) + rspec-mocks (2.6.0) ruby2ruby (1.2.4) ruby_parser (~> 2.0) sexp_processor (~> 3.0) ruby_parser (2.0.4) sexp_processor (~> 3.0) sexp_processor (3.0.4) + thor (0.14.6) PLATFORMS ruby DEPENDENCIES apache-config-generator! - autotest bundler (>= 1.0.0) + guard + guard-rspec mocha nokogiri - rainbow reek - rspec (~> 2.0.0) + rspec (~> 2.6.0) diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..eed3765 --- /dev/null +++ b/Guardfile @@ -0,0 +1,9 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +guard 'rspec', :version => 2 do + watch(%r{^spec/.+_spec\.rb$}) + watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } + watch('spec/spec_helper.rb') { "spec" } +end + diff --git a/apache-config-generator.gemspec b/apache-config-generator.gemspec index 8bc2df8..189618e 100644 --- a/apache-config-generator.gemspec +++ b/apache-config-generator.gemspec @@ -22,10 +22,11 @@ Gem::Specification.new do |s| s.required_rubygems_version = ">= 1.3.6" s.add_development_dependency "bundler", ">= 1.0.0" - s.add_development_dependency "rspec", "~> 2.0.0" + s.add_development_dependency "rspec", "~> 2.6.0" s.add_development_dependency "nokogiri" s.add_development_dependency "mocha" - s.add_development_dependency "autotest" + s.add_development_dependency 'guard' + s.add_development_dependency 'guard-rspec' s.add_development_dependency "reek" s.add_dependency 'rainbow' diff --git a/lib/apache.rb b/lib/apache.rb index d49c9b4..59bbfc7 100644 --- a/lib/apache.rb +++ b/lib/apache.rb @@ -1 +1,23 @@ -require 'apache/config' +module Apache + autoload :Apachify, 'apache/apachify' + autoload :Config, 'apache/config' + autoload :Directories, 'apache/directory' + autoload :Logging, 'apache/logging' + autoload :Master, 'apache/master' + autoload :Modules, 'apache/modules' + autoload :Performance, 'apache/performance' + autoload :Permissions, 'apache/permissions' + autoload :Rewrites, 'apache/rewrites' + autoload :SSL, 'apache/ssl' + autoload :MPM, 'apache/mpm_prefork' + + module Rake + autoload :Support, 'apache/rake/support' + end +end + +require 'apache/core_ext/hash' +require 'apache/core_ext/string' +require 'apache/core_ext/symbol' +require 'apache/core_ext/fixnum' +require 'apache/core_ext/array' diff --git a/lib/apache/apachify.rb b/lib/apache/apachify.rb index 4fd4d7d..247b736 100644 --- a/lib/apache/apachify.rb +++ b/lib/apache/apachify.rb @@ -21,121 +21,3 @@ module Apache end end -# Ruby strings -class String - include Apache::Apachify - - alias :optionify :apachify - - def commentize - self.split("\n") - end - - def quoteize - %{"#{self}"} - end - - alias :blockify :quoteize - - def headerize - "#{self.quoteize}" - end - - def replace_placeholderize(opts) - self.gsub(%r{%\{([^\}]+)\}}) do |match| - key = $1.downcase.to_sym - opts[key] || '' - end - end -end - -# Ruby symbols -class Symbol - include Apache::Apachify - - # Turn this into an option for IndexOptions - def optionify - output = self.apachify - output = "-#{output[3..-1]}" if self.to_s[0..3] == 'not_' - output - end - - def quoteize - self.to_s.gsub('_', ' ') - end - - def blockify - self.to_s - end - - def headerize - "#{self.quoteize}" - end -end - -class Fixnum - def quoteize; self; end -end - -# Ruby arrays -class Array - # Apachify all the elements within this array - def apachify - self.collect(&:apachify) - end - - def quoteize - self.collect(&:quoteize) - end - - def quoteize! - self.collect!(&:quoteize) - end - - def blockify - self.quoteize * " " - end - - alias :commentize :to_a - - def headerize - "#{self.first.quoteize} #{self.last}" - end - - def rewrite_cond_optionify - self.collect do |opt| - { - :or => 'OR', - :case_insensitive => 'NC', - :no_vary => 'NV' - }[opt] - end - end - - def rewrite_option_listify - (!self.empty?) ? "[#{self * ','}]" : nil - end -end - -# Ruby hashes -class Hash - REWRITE_RULE_CONDITIONS = { - :last => 'L', - :forbidden => 'F', - :no_escape => 'NE', - :redirect => lambda { |val| val == true ? 'R' : "R=#{val}" }, - :pass_through => 'PT', - :preserve_query_string => 'QSA', - :query_string_append => 'QSA', - :proxy => 'P', - :env => lambda { |val| "E=#{val}" } - } - - def rewrite_rule_optionify - self.collect do |key, value| - what = REWRITE_RULE_CONDITIONS[key] - what = what.call(value) if what.kind_of? Proc - what - end.compact.sort - end -end diff --git a/lib/apache/config.rb b/lib/apache/config.rb index 9b08e4b..642ec22 100644 --- a/lib/apache/config.rb +++ b/lib/apache/config.rb @@ -1,10 +1,6 @@ require 'fileutils' require 'rainbow' -%w{apachify directory logging master modules mpm_prefork performance permissions rewrites ssl}.each do |file| - require "apache/#{file}" -end - module Apache # The core class of Apache Config Generator. # diff --git a/lib/apache/core_ext/array.rb b/lib/apache/core_ext/array.rb new file mode 100644 index 0000000..ff5b8b8 --- /dev/null +++ b/lib/apache/core_ext/array.rb @@ -0,0 +1,40 @@ +# Ruby arrays +class Array + # Apachify all the elements within this array + def apachify + self.collect(&:apachify) + end + + def quoteize + self.collect(&:quoteize) + end + + def quoteize! + self.collect!(&:quoteize) + end + + def blockify + self.quoteize * " " + end + + alias :commentize :to_a + + def headerize + "#{self.first.quoteize} #{self.last}" + end + + def rewrite_cond_optionify + self.collect do |opt| + { + :or => 'OR', + :case_insensitive => 'NC', + :no_vary => 'NV' + }[opt] + end + end + + def rewrite_option_listify + (!self.empty?) ? "[#{self * ','}]" : nil + end +end + diff --git a/lib/apache/core_ext/fixnum.rb b/lib/apache/core_ext/fixnum.rb new file mode 100644 index 0000000..2823a5b --- /dev/null +++ b/lib/apache/core_ext/fixnum.rb @@ -0,0 +1,4 @@ +class Fixnum + def quoteize; self; end +end + diff --git a/lib/apache/core_ext/hash.rb b/lib/apache/core_ext/hash.rb new file mode 100644 index 0000000..22cf9f4 --- /dev/null +++ b/lib/apache/core_ext/hash.rb @@ -0,0 +1,28 @@ +class Hash + def to_sym_keys + Hash[self.collect { |key, value| + value = value.to_sym_keys if value.kind_of?(Hash) + [ key.to_sym, value ] + }] + end + + REWRITE_RULE_CONDITIONS = { + :last => 'L', + :forbidden => 'F', + :no_escape => 'NE', + :redirect => lambda { |val| val == true ? 'R' : "R=#{val}" }, + :pass_through => 'PT', + :preserve_query_string => 'QSA', + :query_string_append => 'QSA', + :proxy => 'P', + :env => lambda { |val| "E=#{val}" } + } + + def rewrite_rule_optionify + self.collect do |key, value| + what = REWRITE_RULE_CONDITIONS[key] + what = what.call(value) if what.kind_of? Proc + what + end.compact.sort + end +end diff --git a/lib/apache/core_ext/string.rb b/lib/apache/core_ext/string.rb new file mode 100644 index 0000000..cb8ce1d --- /dev/null +++ b/lib/apache/core_ext/string.rb @@ -0,0 +1,28 @@ +# Ruby strings +class String + include Apache::Apachify + + alias :optionify :apachify + + def commentize + self.split("\n") + end + + def quoteize + %{"#{self}"} + end + + alias :blockify :quoteize + + def headerize + "#{self.quoteize}" + end + + def replace_placeholderize(opts) + self.gsub(%r{%\{([^\}]+)\}}) do |match| + key = $1.downcase.to_sym + opts[key] || '' + end + end +end + diff --git a/lib/apache/core_ext/symbol.rb b/lib/apache/core_ext/symbol.rb new file mode 100644 index 0000000..c9dc58d --- /dev/null +++ b/lib/apache/core_ext/symbol.rb @@ -0,0 +1,24 @@ +# Ruby symbols +class Symbol + include Apache::Apachify + + # Turn this into an option for IndexOptions + def optionify + output = self.apachify + output = "-#{output[3..-1]}" if self.to_s[0..3] == 'not_' + output + end + + def quoteize + self.to_s.gsub('_', ' ') + end + + def blockify + self.to_s + end + + def headerize + "#{self.quoteize}" + end +end + diff --git a/lib/apache/hash.rb b/lib/apache/hash.rb deleted file mode 100644 index 94013ff..0000000 --- a/lib/apache/hash.rb +++ /dev/null @@ -1,8 +0,0 @@ -class Hash - def to_sym_keys - Hash[self.collect { |key, value| - value = value.to_sym_keys if value.kind_of?(Hash) - [ key.to_sym, value ] - }] - end -end \ No newline at end of file diff --git a/lib/apache/rake/apache/create.rb b/lib/apache/rake/apache/create.rb index 9b8f915..64097c1 100644 --- a/lib/apache/rake/apache/create.rb +++ b/lib/apache/rake/apache/create.rb @@ -1,5 +1,4 @@ -require 'apache/config' -require 'apache/rake/support' +require 'apache' include Apache::Rake::Support diff --git a/lib/apache/rake/support.rb b/lib/apache/rake/support.rb index 49c6f6f..e6fc6a1 100644 --- a/lib/apache/rake/support.rb +++ b/lib/apache/rake/support.rb @@ -1,6 +1,5 @@ require 'yaml' require 'fileutils' -require 'apache/hash' module Apache module Rake diff --git a/lib/apache/rewrites.rb b/lib/apache/rewrites.rb index 6b1c5b5..9f16770 100644 --- a/lib/apache/rewrites.rb +++ b/lib/apache/rewrites.rb @@ -1,5 +1,3 @@ -require 'pp' - module Apache # Handle the creation of RewriteRules, RewriteConds, Redirects, and RedirectMatches module Rewrites diff --git a/spec/apache/apachify_spec.rb b/spec/apache/apachify_spec.rb index 3580a5e..31a4368 100644 --- a/spec/apache/apachify_spec.rb +++ b/spec/apache/apachify_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require 'apache/apachify' describe Apache::Apachify, "extends objects to apachify themselves" do it "should Apachify the name" do diff --git a/spec/apache/config_spec.rb b/spec/apache/config_spec.rb index 6a06202..ecbc996 100644 --- a/spec/apache/config_spec.rb +++ b/spec/apache/config_spec.rb @@ -1,4 +1,4 @@ -require 'apache/config' +require 'spec_helper' require 'fileutils' describe Apache::Config, "builds configurations" do diff --git a/spec/apache/directory_spec.rb b/spec/apache/directory_spec.rb index 8d835ac..33dd8f2 100644 --- a/spec/apache/directory_spec.rb +++ b/spec/apache/directory_spec.rb @@ -1,4 +1,4 @@ -require 'apache/config' +require 'spec_helper' describe Apache::Master, "should provide basic helpers for configuration" do let(:apache) { Apache::Config } diff --git a/spec/apache/hash_spec.rb b/spec/apache/hash_spec.rb index 7eea9d3..05ac5e5 100644 --- a/spec/apache/hash_spec.rb +++ b/spec/apache/hash_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require 'lib/apache/hash' describe Hash do describe '#to_sym_keys' do diff --git a/spec/apache/logging_spec.rb b/spec/apache/logging_spec.rb index a04b99f..95333d5 100644 --- a/spec/apache/logging_spec.rb +++ b/spec/apache/logging_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require 'apache/config' describe Apache::Config, "logging directives" do let(:apache) { Apache::Config } diff --git a/spec/apache/rake/support_spec.rb b/spec/apache/rake/support_spec.rb index b0c463f..33105aa 100644 --- a/spec/apache/rake/support_spec.rb +++ b/spec/apache/rake/support_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require 'apache/rake/support' describe Apache::Rake::Support do include Apache::Rake::Support @@ -20,4 +19,4 @@ describe Apache::Rake::Support do its([:source_path]) { should == File.expand_path('cats') } its([:destination_path]) { should == File.expand_path('dogs') } end -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b9a1fd4..c64db0b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ -Rspec.configure do |config| +require 'apache' + +RSpec.configure do |config| config.mock_with :mocha end diff --git a/tools.watchr b/tools.watchr deleted file mode 100644 index d736aa7..0000000 --- a/tools.watchr +++ /dev/null @@ -1,22 +0,0 @@ -def growl(title, message) - system %{growlnotify -m "#{message}" "#{title}"} -end - -def reek(file) - output = %x{reek #{file}} - - puts output - - file, warnings = output.split("\n").first.split(" -- ") - - growl "REEK: #{file}", warnings -end - -def yard - system %{yard doc {app,lib}/**/*.rb} -end - -watch('(app|lib)/(.*)\.rb') { |match| - reek(match[0]) - yard -}