Commits

Michael Granger  committed d546cf3

Fixes for Ruby 1.9.2

  • Participants
  • Parent commits cd52868

Comments (0)

Files changed (7)

 	basedir = Pathname.new( __FILE__ ).dirname
 	libdir = basedir + "lib"
 
+	puts ">>> Adding #{basedir} to load path..."
+	$LOAD_PATH.unshift( basedir.to_s )
+
 	puts ">>> Adding #{libdir} to load path..."
 	$LOAD_PATH.unshift( libdir.to_s )
 

File lib/thingfish/config.rb

 
 	### Returns +true+ for methods which can be autoloaded
 	def respond_to?( sym )
-		return true if @struct.member?( sym.to_s.sub(/(=|\?)$/, '').to_sym )
+		self.log.debug "Checking response to %p message..." % [ sym ]
+		key = sym.to_s.sub( /(=|\?)$/, '' ).to_sym
+		self.log.debug "  normalized key is: %p, struct members are: %p" % [ key, @struct.members ]
+		return true if @struct.member?( key )
 		super
 	end
 
 		key = sym.to_s.sub( /(=|\?)$/, '' ).to_sym
 		return nil unless @struct.member?( key )
 
-		self.class.class_eval %{
-			def #{key}; @struct.#{key}; end
-			def #{key}=(arg); @struct.#{key} = arg; end
-			def #{key}?; @struct.#{key}?; end
-		}
+		reader    = lambda { @struct[key] }
+		writer    = lambda {|arg| @struct[key] = arg }
+		predicate = lambda { @struct.send("#{key}?") }
+
+		self.class.send( :define_method, key, &reader )
+		self.class.send( :define_method, "#{key}=", &writer )
+		self.class.send( :define_method, "${key}?", &predicate )
 
 		return self.method( sym ).call( *args )
 	end
 	### Hash-wrapper that allows struct-like accessor calls on nested
 	### hashes.
 	class ConfigStruct
-		include Enumerable, ThingFish::Loggable
+		include Enumerable,
+		        ThingFish::Loggable
 		extend Forwardable
 
 		# Mask most of Kernel's methods away so they don't collide with
 		# config values.
 		Kernel.methods(false).each {|meth|
 			next unless method_defined?( meth )
-			next if /^(?:__|dup|object_id|inspect|class|raise|method_missing)/.match( meth )
+			next if /^(?:__|dup|object_id|inspect|class|raise|method_missing|log)/.match( meth )
 			undef_method( meth )
 		}
 
 		attr_writer :modified
 
 
+		### Return a human-readable representation of the object suitable for
+		### debugging.
+		def inspect
+			default = super
+			return "#<%p 0x%0x: %s (%s)>" % [
+				self.class,
+				self.object_id * 2,
+				default,
+				self.modified? ? "modified" : "not modified"
+			]
+		end
+
+
 		### Returns +true+ if the ConfigStruct or any of its sub-structs
 		### have changed since it was created.
 		def modified?
 		### Return +true+ if the receiver responds to the given
 		### method. Overridden to grok autoloaded methods.
 		def respond_to?( sym, priv=false )
+			raise "Chumba!"
+			self.log.debug "Checking response to %p message..." % [ sym ]
 			key = sym.to_s.sub( /(=|\?)$/, '' ).to_sym
+			self.log.debug "  normalized key is: %p, hash keys are: %p" % [ key, @hash.keys ]
 			return true if @hash.key?( key )
 			super
 		end

File plugins/thingfish-filestore-filesystem/lib/thingfish/filestore/filesystem.rb

 		:poll_max_sleep => 0.08,
 		:dont_clean     => false,
 		:dont_sweep     => false,
-		:debug			=> false,
+		:debug			=> true,
 	}
 
 

File plugins/thingfish-filestore-filesystem/spec/thingfish/filestore/filesystem_spec.rb

 
 require 'pathname'
 require 'tmpdir'
+require 'lockfile'
 require 'thingfish/filestore/filesystem'
 
 
+class Lockfile
+	def trace( s=nil )
+		s ||= yield
+		ThingFish.logger.debug( s )
+	end
+end
+
+
 #####################################################################
 ###	C O N T E X T S
 #####################################################################
 
 # protected -> public for testing ease
-#
 class ThingFish::FilesystemFileStore
 	public :sizecache
 end
 		before(:each) do
 			lockopts = ThingFish::FilesystemFileStore::DEFAULT_LOCKING_OPTIONS
 			lockopts[ :debug ] = true
-			
-		    @fs = ThingFish::FileStore.create( 'filesystem', @tmpdir, @spooldir, :locking => lockopts )
+
+		    @fs = ThingFish::FileStore.create( 'filesystem', @tmpdir, @spooldir,
+		 		:locking => lockopts )
 			@io = StringIO.new( TEST_RESOURCE_CONTENT )
 		end
 

File spec/lib/filestore_behavior.rb

 
 BEGIN {
 	require 'pathname'
-	basedir = Pathname.new( __FILE__ ).dirname.parent
+	basedir = Pathname.new( __FILE__ ).dirname.parent.parent
 
 	libdir = basedir + "lib"
 

File spec/spec.opts

--r
-loadpath.rb
 -f
 s
 -c
+-Du

File spec/thingfish/config_spec.rb

 	include ThingFish::SpecHelpers
 
 	before( :all ) do
-		setup_logging( :fatal )
+		setup_logging( :debug )
 
 		@test_config = %{
 		---
 	end
 
 	it "responds to methods which are the same as struct members" do
-		@config.respond_to?( :ip ).should == true
-		@config.plugins.respond_to?( :urimap ).should == true
+		@config.should respond_to( :ip )
+		plugins = @config.plugins
+		ThingFish.logger.debug "@config.plugins is a %p: %p" % [ plugins.class, plugins ]
+		plugins.should respond_to( :urimap )
 		@config.respond_to?( :pork_sausage ).should == false
 	end