Michael Granger avatar Michael Granger committed a0ed858

Give instances of loghost classes logclient instance methods.

- Reorganized the specs to separate loghost and logclient APIs
- Rearranged the class/method declarations in loggability.rb.
- Updated development dependencies.

Comments (0)

Files changed (4)

 # .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
-configurability -v1.2.0
-rdoc -v3.12
-simplecov -v0.6.2
+hoe-deveiate -v0.2.0
+configurability -v2.0.0
+rdoc -v4.0.0
+simplecov -v0.7.1
 excludeInFileChooser = "{$exclude,.hg,pkg}"
 
 [ source.ruby ]
+softTabs = false
+tabSize = 4
 disableIndentCorrections = true
 
+[ source.ruby.rspec ]
+softTabs = false
+tabSize = 4
+

lib/loggability.rb

 	end # module LogHost
 
 
-	#
-	# :section: LogHost API
-	#
-
-	### Register as a log host associated with the given +key+, add the methods from
-	### LogHost, and install a Loggability::Logger.
-	def log_as( key )
-		self.extend( Loggability::LogHost )
-		self.log_host_key = key.to_sym
-		self.logger = self.default_logger = Loggability::Logger.new
-		Loggability.register_loghost( self )
-	end
-
-	# Install a global logger in Loggability itself
-	extend( Loggability::LogHost )
-	self.log_host_key = GLOBAL_KEY
-	self.logger = self.default_logger = Loggability::Logger.new
-	Loggability.register_loghost( self )
-
-
-
 	# Methods to install for objects which call +log_to+.
 	module LogClient
 
 
 
 	#
+	# :section: LogHost API
+	#
+
+	### Register as a log host associated with the given +key+, add the methods from
+	### LogHost, and install a Loggability::Logger.
+	def log_as( key )
+		extend( Loggability::LogHost )
+		include( Loggability::LogClient::InstanceMethods ) if self.is_a?( Class )
+
+		self.log_host_key = key.to_sym
+		self.logger = self.default_logger = Loggability::Logger.new
+		Loggability.register_loghost( self )
+	end
+
+
+	#
 	# :section: LogClient API
 	#
 
 	end
 
 
+	# Install a global logger in Loggability itself
+	extend( Loggability::LogHost )
+	self.log_host_key = GLOBAL_KEY
+	self.logger = self.default_logger = Loggability::Logger.new
+	Loggability.register_loghost( self )
+
+
 	#
 	# :section: Configurability Support
 	#

spec/loggability_spec.rb

 	end
 
 
-	context "installed in a class" do
+	context "installed in a class as a log host" do
 
 		before( :each ) do
-			@class = Class.new { extend Loggability }
+			@class = Class.new do
+				extend Loggability
+				log_as :testing
+			end
 		end
 
 		after( :each ) do
 		end
 
 
-		it "allows it to be designated as a log host" do
-			@class.log_as( :testing )
+		it "is included in the list of log hosts" do
 			Loggability.log_hosts.should include( :testing => @class )
+		end
+
+		it "has an associated Loggability::Logger" do
 			@class.logger.should be_a( Loggability::Logger )
+		end
+
+		it "has an associated default Loggability::Logger" do
 			@class.default_logger.should be( @class.logger )
+		end
+
+		it "registers itself with the Loggability module" do
 			Loggability[ @class ].should be( @class.logger )
+		end
+
+		it "registers its key with the Loggability module" do
 			Loggability[ :testing ].should be( @class.logger )
 		end
 
-		it "allows it to designate itself as a logging client" do
-			origin = Class.new do
-				extend Loggability
-				log_as :testing
-			end
-			@class.log_to( :testing )
-			@class.log.logger.should be( origin.logger )
-			Loggability[ @class ].should be( origin.logger )
-
-			obj = @class.new
-
-			obj.log.logger.should be( origin.logger )
-			Loggability[ obj ].should be( origin.logger )
-		end
-
-		it "propagates its log host key to subclasses" do
-			origin = Class.new do
-				extend Loggability
-				log_as :testing
-			end
-			@class.log_to( :testing )
-			subclass = Class.new( @class )
-
-			subclass.log.logger.should be( origin.logger )
-			Loggability[ subclass ].should be( origin.logger )
+		it "has a proxy for its logger in its instances" do
+			@class.new.log.logger.should be( @class.logger )
 		end
 
 		it "wraps Logger instances assigned as its logger in a Loggability::Logger" do
-			@class.log_as( :testing )
-
 			logger = ::Logger.new( $stderr )
 
 			@class.logger = logger
 
 	end
 
+	context "installed in a class as a logging client" do
+
+		before( :each ) do
+			@loghost = Module.new do
+				extend Loggability
+				log_as :testing
+			end
+
+			@class = Class.new do
+				extend Loggability
+				log_to :testing
+			end
+		end
+
+		after( :each ) do
+			Loggability.clear_loghosts
+		end
+
+
+		it "has a proxy for its log host's logger" do
+			@class.log.logger.should be( @loghost.logger )
+		end
+
+		it "is associated with its log host's logger through the Loggability module" do
+			Loggability[ @class ].should be( @loghost.logger )
+		end
+
+		it "has a proxy for its log host's logger available from its instances" do
+			obj = @class.new
+			obj.log.logger.should be( @loghost.logger )
+		end
+
+
+		it "is associated with its log host's logger via its instances through the Loggability module" do
+			obj = @class.new
+			Loggability[ obj ].should be( @loghost.logger )
+		end
+
+		it "propagates its log host key to subclasses" do
+			subclass = Class.new( @class )
+			subclass.log.logger.should be( @loghost.logger )
+			Loggability[ subclass ].should be( @loghost.logger )
+		end
+
+	end
+
 
 	context "aggregate methods" do
 
-		it "propagate some setting methods to every Logger" do
-			origin = Class.new do
+		before( :each ) do
+			Loggability.clear_loghosts
+			@loghost = Class.new do
 				extend Loggability
 				log_as :testing
 			end
+		end
+
+
+		it "can propagate a logging level to every loghost" do
 			Loggability.level = :warn
+			Loggability[ @loghost ].level.should == :warn
+		end
+
+		it "can propagate an outputter to every loghost" do
 			Loggability.output_to( $stdout )
+			Loggability[ @loghost ].logdev.dev.should be( $stdout )
+		end
+
+		it "can propagate a formatter to every loghost" do
 			Loggability.format_with( :color )
-
-			Loggability[ origin ].level.should == :warn
-			Loggability[ origin ].logdev.dev.should be( $stdout )
-			Loggability[ origin ].formatter.class.should == Loggability::Formatter::Color
+			Loggability[ @loghost ].formatter.should be_a( Loggability::Formatter::Color )
 		end
 
 	end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.