class Object

Constants

Ib
IbRuby

Public Instance Methods

default_logger() click to toggle source

Add default_logger accessor into Object

# 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"
      "#{time.strftime('%Y-%m-%d %H:%M:%S')} #{msg}\n"
      # Hardcoded 20201204 by PA!
    end
    logger.level = Logger::INFO
  end
end
default_logger=(logger) click to toggle source
# File lib/ib/logger.rb, line 16
def default_logger= logger
  @default_logger = logger
end
error(message, type=:standard, backtrace=nil) click to toggle source

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.

# 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) click to toggle source

Add universally accessible log method/accessor into Object

# File lib/ib/logger.rb, line 21
def log *args
  default_logger.tap do |logger|
    logger.fatal *args unless args.empty?
  end
end
to_sup() click to toggle source

We still need to pass on nil, meaning: no value

# File lib/ib/extensions.rb, line 61
def to_sup
  self.to_s.upcase unless self.nil?
end