rearrange some things to make it more modern

This commit is contained in:
John Bintz 2011-09-27 15:30:38 -04:00
parent d694b09bf6
commit 760d36766b
23 changed files with 183 additions and 183 deletions

View File

@ -7,8 +7,11 @@ PATH
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
autotest (4.4.2) diff-lcs (1.1.3)
diff-lcs (1.1.2) guard (0.7.0)
thor (~> 0.14.6)
guard-rspec (0.4.5)
guard (>= 0.4.0)
mocha (0.9.10) mocha (0.9.10)
rake rake
nokogiri (1.4.3.1) nokogiri (1.4.3.1)
@ -18,32 +21,31 @@ GEM
ruby2ruby (~> 1.2) ruby2ruby (~> 1.2)
ruby_parser (~> 2.0) ruby_parser (~> 2.0)
sexp_processor (~> 3.0) sexp_processor (~> 3.0)
rspec (2.0.1) rspec (2.6.0)
rspec-core (~> 2.0.1) rspec-core (~> 2.6.0)
rspec-expectations (~> 2.0.1) rspec-expectations (~> 2.6.0)
rspec-mocks (~> 2.0.1) rspec-mocks (~> 2.6.0)
rspec-core (2.0.1) rspec-core (2.6.4)
rspec-expectations (2.0.1) rspec-expectations (2.6.0)
diff-lcs (>= 1.1.2) diff-lcs (~> 1.1.2)
rspec-mocks (2.0.1) rspec-mocks (2.6.0)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
ruby2ruby (1.2.4) ruby2ruby (1.2.4)
ruby_parser (~> 2.0) ruby_parser (~> 2.0)
sexp_processor (~> 3.0) sexp_processor (~> 3.0)
ruby_parser (2.0.4) ruby_parser (2.0.4)
sexp_processor (~> 3.0) sexp_processor (~> 3.0)
sexp_processor (3.0.4) sexp_processor (3.0.4)
thor (0.14.6)
PLATFORMS PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
apache-config-generator! apache-config-generator!
autotest
bundler (>= 1.0.0) bundler (>= 1.0.0)
guard
guard-rspec
mocha mocha
nokogiri nokogiri
rainbow
reek reek
rspec (~> 2.0.0) rspec (~> 2.6.0)

9
Guardfile Normal file
View File

@ -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

View File

@ -22,10 +22,11 @@ Gem::Specification.new do |s|
s.required_rubygems_version = ">= 1.3.6" s.required_rubygems_version = ">= 1.3.6"
s.add_development_dependency "bundler", ">= 1.0.0" 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 "nokogiri"
s.add_development_dependency "mocha" 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_development_dependency "reek"
s.add_dependency 'rainbow' s.add_dependency 'rainbow'

View File

@ -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'

View File

@ -21,121 +21,3 @@ module Apache
end end
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

View File

@ -1,10 +1,6 @@
require 'fileutils' require 'fileutils'
require 'rainbow' require 'rainbow'
%w{apachify directory logging master modules mpm_prefork performance permissions rewrites ssl}.each do |file|
require "apache/#{file}"
end
module Apache module Apache
# The core class of Apache Config Generator. # The core class of Apache Config Generator.
# #

View File

@ -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

View File

@ -0,0 +1,4 @@
class Fixnum
def quoteize; self; end
end

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,5 +1,4 @@
require 'apache/config' require 'apache'
require 'apache/rake/support'
include Apache::Rake::Support include Apache::Rake::Support

View File

@ -1,6 +1,5 @@
require 'yaml' require 'yaml'
require 'fileutils' require 'fileutils'
require 'apache/hash'
module Apache module Apache
module Rake module Rake

View File

@ -1,5 +1,3 @@
require 'pp'
module Apache module Apache
# Handle the creation of RewriteRules, RewriteConds, Redirects, and RedirectMatches # Handle the creation of RewriteRules, RewriteConds, Redirects, and RedirectMatches
module Rewrites module Rewrites

View File

@ -1,5 +1,4 @@
require 'spec_helper' require 'spec_helper'
require 'apache/apachify'
describe Apache::Apachify, "extends objects to apachify themselves" do describe Apache::Apachify, "extends objects to apachify themselves" do
it "should Apachify the name" do it "should Apachify the name" do

View File

@ -1,4 +1,4 @@
require 'apache/config' require 'spec_helper'
require 'fileutils' require 'fileutils'
describe Apache::Config, "builds configurations" do describe Apache::Config, "builds configurations" do

View File

@ -1,4 +1,4 @@
require 'apache/config' require 'spec_helper'
describe Apache::Master, "should provide basic helpers for configuration" do describe Apache::Master, "should provide basic helpers for configuration" do
let(:apache) { Apache::Config } let(:apache) { Apache::Config }

View File

@ -1,5 +1,4 @@
require 'spec_helper' require 'spec_helper'
require 'lib/apache/hash'
describe Hash do describe Hash do
describe '#to_sym_keys' do describe '#to_sym_keys' do

View File

@ -1,5 +1,4 @@
require 'spec_helper' require 'spec_helper'
require 'apache/config'
describe Apache::Config, "logging directives" do describe Apache::Config, "logging directives" do
let(:apache) { Apache::Config } let(:apache) { Apache::Config }

View File

@ -1,5 +1,4 @@
require 'spec_helper' require 'spec_helper'
require 'apache/rake/support'
describe Apache::Rake::Support do describe Apache::Rake::Support do
include Apache::Rake::Support include Apache::Rake::Support
@ -20,4 +19,4 @@ describe Apache::Rake::Support do
its([:source_path]) { should == File.expand_path('cats') } its([:source_path]) { should == File.expand_path('cats') }
its([:destination_path]) { should == File.expand_path('dogs') } its([:destination_path]) { should == File.expand_path('dogs') }
end end
end end

View File

@ -1,3 +1,5 @@
Rspec.configure do |config| require 'apache'
RSpec.configure do |config|
config.mock_with :mocha config.mock_with :mocha
end end

View File

@ -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
}