Top Level Namespace

Defined Under Namespace

Modules: IB, Ib Classes: FalseClass, NilClass, Numeric, Object, String, Symbol, Time, TrueClass

Constant Summary collapse

IbRuby =

module IB

IB

Instance Method Summary collapse

Instance Method Details

#default_loggerObject

Add default_logger accessor into Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/ib/logger.rb', line 4

def default_logger
  @@default_logger ||= Logger.new(STDOUT).tap do |logger|
    time_format = RUBY_VERSION =~ /1\.8\./ ? '%H:%M:%S.%N' : '%H:%M:%S.%3N'
    logger.formatter = proc do |level, time, prog, msg|

      "#{time.strftime(time_format)} #{msg}\n"
    end
    logger.level = Logger::INFO
  end
end

#default_logger=(logger) ⇒ Object



15
16
17
# File 'lib/ib/logger.rb', line 15

def default_logger= logger
  @@default_logger = logger
end

#error(message, type = :standard, backtrace = nil) ⇒ Object

Patching Object with universally accessible top level error method. The method is used throughout the lib instead of plainly raising exceptions. This allows lib user to easily inject user-specific error handling into the lib by just replacing Object#error method.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ib/errors.rb', line 25

def error message, type=:standard, backtrace=nil
  e = case type
  when :standard
    IB::Error.new message
  when :args
    IB::ArgumentError.new message
  when :symbol
    IB::SymbolError.new message
  when :load
    IB::LoadError.new message
  when :flex
    IB::FlexError.new message
  end
  e.set_backtrace(backtrace) if backtrace
  raise e
end

#log(*args) ⇒ Object

Add universally accessible log method/accessor into Object



20
21
22
23
24
# File 'lib/ib/logger.rb', line 20

def log *args
  default_logger.tap do |logger|
    logger.fatal *args unless args.empty?
  end
end