Browse files

CHORE: Replaced mutex with monitor

  • Loading branch information...
1 parent f49ad34 commit ae4d90f5eefb0c7a32dac078f9793d25586a1e8d @rudionrails committed Sep 21, 2012
Showing with 11 additions and 14 deletions.
  1. +3 −7 lib/yell/adapters/base.rb
  2. +6 −1 lib/yell/adapters/file.rb
  3. +2 −6 spec/yell/adapters/file_spec.rb
View
10 lib/yell/adapters/base.rb
@@ -1,6 +1,6 @@
# encoding: utf-8
-require 'thread'
+require 'monitor'
module Yell #:nodoc:
module Adapters #:nodoc:
@@ -40,7 +40,7 @@ module Adapters #:nodoc:
#
# logger = Yell.new :puts
# logger.info "Hello World!"
- class Base
+ class Base < Monitor
include Yell::Level::Helpers
class << self
@@ -125,7 +125,7 @@ def define!( name, _m, m, &block )
#
# You should not overload the constructor, use #setup instead.
def initialize( options = {}, &block )
- @mutex = Mutex.new
+ super() # init the monitor superclass
setup!(options)
block.call(self) if block
@@ -191,10 +191,6 @@ def write?( event )
@level.nil? || @level.at?( event.level )
end
- def synchronize( &block )
- @mutex.synchronize( &block )
- end
-
end
end
View
7 lib/yell/adapters/file.rb
@@ -14,14 +14,19 @@ class File < Yell::Adapters::Io
self.sync = options.fetch(:sync, true)
end
+
+ # Sets the “sync mode” to true or false.
+ #
+ # When true (default), every log event is immediately written to the file.
+ # When false, the log event is buffered internally.
attr_accessor :sync
private
# @overload Lazily open the file handle
def stream
- @stream or open!
+ synchronize { @stream or open! }
end
def open!
View
8 spec/yell/adapters/file_spec.rb
@@ -44,19 +44,15 @@
let( :adapter ) { Yell::Adapters::File.new }
it "should sync by default" do
- any_instance_of( File ) do |file|
- mock( file ).sync=( true )
- end
+ mock( devnull ).sync=( true )
adapter.write( event )
end
it "pass the option to File" do
adapter.sync = false
- any_instance_of( File ) do |file|
- mock( file ).sync=( false )
- end
+ mock( devnull ).sync=( false )
adapter.write( event )
end

0 comments on commit ae4d90f

Please sign in to comment.