Skip to content

Commit

Permalink
CHORE: Replaced mutex with monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
rudionrails committed Sep 21, 2012
1 parent f49ad34 commit ae4d90f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
10 changes: 3 additions & 7 deletions lib/yell/adapters/base.rb
@@ -1,6 +1,6 @@
# encoding: utf-8 # encoding: utf-8


require 'thread' require 'monitor'


module Yell #:nodoc: module Yell #:nodoc:
module Adapters #:nodoc: module Adapters #:nodoc:
Expand Down Expand Up @@ -40,7 +40,7 @@ module Adapters #:nodoc:
# #
# logger = Yell.new :puts # logger = Yell.new :puts
# logger.info "Hello World!" # logger.info "Hello World!"
class Base class Base < Monitor
include Yell::Level::Helpers include Yell::Level::Helpers


class << self class << self
Expand Down Expand Up @@ -125,7 +125,7 @@ def define!( name, _m, m, &block )
# #
# You should not overload the constructor, use #setup instead. # You should not overload the constructor, use #setup instead.
def initialize( options = {}, &block ) def initialize( options = {}, &block )
@mutex = Mutex.new super() # init the monitor superclass


setup!(options) setup!(options)
block.call(self) if block block.call(self) if block
Expand Down Expand Up @@ -191,10 +191,6 @@ def write?( event )
@level.nil? || @level.at?( event.level ) @level.nil? || @level.at?( event.level )
end end


def synchronize( &block )
@mutex.synchronize( &block )
end

end end


end end
Expand Down
7 changes: 6 additions & 1 deletion lib/yell/adapters/file.rb
Expand Up @@ -14,14 +14,19 @@ class File < Yell::Adapters::Io
self.sync = options.fetch(:sync, true) self.sync = options.fetch(:sync, true)
end 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 attr_accessor :sync




private private


# @overload Lazily open the file handle # @overload Lazily open the file handle
def stream def stream
@stream or open! synchronize { @stream or open! }
end end


def open! def open!
Expand Down
8 changes: 2 additions & 6 deletions spec/yell/adapters/file_spec.rb
Expand Up @@ -44,19 +44,15 @@
let( :adapter ) { Yell::Adapters::File.new } let( :adapter ) { Yell::Adapters::File.new }


it "should sync by default" do it "should sync by default" do
any_instance_of( File ) do |file| mock( devnull ).sync=( true )
mock( file ).sync=( true )
end


adapter.write( event ) adapter.write( event )
end end


it "pass the option to File" do it "pass the option to File" do
adapter.sync = false adapter.sync = false


any_instance_of( File ) do |file| mock( devnull ).sync=( false )
mock( file ).sync=( false )
end


adapter.write( event ) adapter.write( event )
end end
Expand Down

0 comments on commit ae4d90f

Please sign in to comment.