Commits

Michael Granger committed 476b2ae

Remove dependency on PluginFactory/Pluggability to avoid circular dependency.

  • Participants
  • Parent commits 740a4e8

Comments (0)

Files changed (5)

 # .gems generated gem export file. Note that any env variable settings will be missing. Append these after using a ';' field separator
 hoe-deveiate -v0.1.1
-pluginfactory -v1.0.8
 configurability -v1.2.0
 rdoc -v3.12
 simplecov -v0.6.2
 
 	self.developer 'Michael Granger', 'ged@FaerieMUD.org'
 
-	self.dependency 'pluginfactory',   '~> 1.0'
-
 	self.dependency 'hoe-deveiate',    '~> 0.1', :developer
 	self.dependency 'simplecov',       '~> 0.6', :developer
 	self.dependency 'configurability', '~> 1.2', :developer

File lib/loggability/formatter.rb

 # vim: set nosta noet ts=4 sw=4:
 # encoding: utf-8
 
-require 'pluginfactory'
-
 require 'loggability' unless defined?( Loggability )
 
 
 ### An abstract base class for Loggability log formatters.
 class Loggability::Formatter
-	extend PluginFactory
 
 	# The default sprintf pattern
 	DEFAULT_DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
 
 
-	### PluginFactory API -- return the Array of paths prefixes to use when searching
-	### formatter plugins.
-	def self::derivative_dirs
-		return ['loggability/formatter']
+	##
+	# Derivative classes, keyed by name
+	class << self; attr_reader :derivatives; end
+	@derivatives = {}
+
+
+	### Inherited hook -- add subclasses to the ::derivatives Array.
+	def self::inherited( subclass )
+		super
+		classname = subclass.name.sub( /.*::/, '' ).downcase.to_sym
+		Loggability::Formatter.derivatives[ classname ] = subclass
 	end
 
 
+	### Create a formatter of the specified +type+, loading it if it hasn't already been
+	### loaded.
+	def self::create( type, *args )
+		require "loggability/formatter/#{type}"
+		type = type.to_sym
+
+		if self.derivatives.key?( type )
+			return self.derivatives[ type ].new( *args )
+		else
+			raise LoadError,
+				"require of %s formatter succeeded (%p), but it didn't load a class named %p::%s" %
+				[ type, self.derivatives, self, type.to_s.capitalize ]
+		end
+	end
+
+
+
 	### Initialize a new Loggability::Formatter. The specified +logformat+ should
 	### be a sprintf pattern with positional placeholders:
 	###

File spec/loggability/formatter_spec.rb

 
 describe Loggability::Formatter do
 
-	it "loads plugins out of loggability/formatter" do
-		Loggability::Formatter.derivative_dirs.should == ['loggability/formatter']
-	end
-
-
 	it "formats messages with the pattern it's constructed with" do
 		formatter = Loggability::Formatter.new( '[%5$s] %7$s' )
 		formatter.call( 'INFO', Time.at(1336286481), nil, 'Foom.' ).should =~

File spec/loggability_spec.rb

 		it "raises an error if configured with a bogus formatter" do
 			expect {
 				Loggability.configure( 'class1' => 'debug (mindwaves)' )
-			}.to raise_error( FactoryError, /couldn't find a formatter/i )
+			}.to raise_error( LoadError, /cannot load such file/i )
 		end
 
 	end