From 55c44f079cc59b6160e363516684670a281efabd Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 18 May 2010 13:20:49 -0400 Subject: [PATCH] more reek work, shifting things arond --- lib/apache/apachify.rb | 18 +++++++++++++++--- lib/apache/config.rb | 19 +------------------ lib/apache/ssl.rb | 3 +-- spec/config_spec.rb | 2 +- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/lib/apache/apachify.rb b/lib/apache/apachify.rb index 9acead8..454a085 100644 --- a/lib/apache/apachify.rb +++ b/lib/apache/apachify.rb @@ -34,6 +34,8 @@ class String def quoteize %{"#{self}"} end + + alias :blockify :quoteize end # Ruby symbols @@ -48,12 +50,18 @@ class Symbol end def quoteize - to_s.gsub('_', ' ') + self.to_s.gsub('_', ' ') + end + + def blockify + self.to_s end end -class Fixnum - def quoteize; to_s; end +# Ruby everything +class Object + alias :quoteize :to_s + alias :blockify :to_s end # Ruby arrays @@ -71,5 +79,9 @@ class Array self.collect!(&:quoteize) end + def blockify + self.quoteize * " " + end + alias :commentize :to_a end diff --git a/lib/apache/config.rb b/lib/apache/config.rb index 04d689c..136f0fb 100644 --- a/lib/apache/config.rb +++ b/lib/apache/config.rb @@ -185,26 +185,9 @@ module Apache self.instance_eval(&block) if env.include?(APACHE_ENV) end - # Blockify the second parameter of a block - # - # The name is processed differently based on input object type: - # * String - the name is quoteized - # * Array - all of the array members are quoteized - # * Symbol - the name is to_s - def blockify_name(name) - case name - when String - name.quoteize.first - when Array - name.quoteize * " " - when Symbol - name.to_s - end - end - # Handle the blockification of a provided block def blockify(tag_name, name, &block) - self + [ '', "<#{[ tag_name, blockify_name(name) ].compact * ' '}>" ] + self + [ '', "<#{[ tag_name, name.blockify ].compact * ' '}>" ] @line_indent += 1 self.instance_eval(&block) @line_indent -= 1 diff --git a/lib/apache/ssl.rb b/lib/apache/ssl.rb index 28d8774..0fc3117 100644 --- a/lib/apache/ssl.rb +++ b/lib/apache/ssl.rb @@ -1,8 +1,7 @@ module Apache module SSL def enable_ssl_engine(options = {}) - self << "" - self << "SSLEngine on" + self + [ '', "SSLEngine on" ] options.each do |key, value| value = quoteize(value).first case key diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 192a777..c772907 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -57,7 +57,7 @@ describe Apache::Config, "builds configurations" do [ :part, 'part' ], [ [ 'part', 'part2' ], '"part" "part2"' ] ].each do |name, attribute| - apache.blockify_name(name).should == attribute + name.blockify.should == attribute end end