1# Copyright (c) 2006-2008, The RubyCocoa Project. 2# Copyright (c) 2001-2006, FUJIMOTO Hisakuni. 3# All Rights Reserved. 4# 5# RubyCocoa is free software, covered under either the Ruby's license or the 6# LGPL. See the COPYRIGHT file for more information. 7 8module OSX 9 10 module BundleSupport 11 12 def init_for_bundle(option = nil) 13 ret = nil 14 bdl, prm = _current_bundle 15 logger = Logger.new(bdl) 16 logger.info("init_for_bundle ...") if OSX._debug? || (option && option[:verbose]) 17 yield(bdl, prm, logger) 18 logger.info("init_for_bundle done.") if OSX._debug? || (option && option[:verbose]) 19 nil 20 rescue Exception => err 21 logger.error(err) 22 logger.info("init_for_bundle failed.") 23 raise 24 end 25 module_function :init_for_bundle 26 27 private 28 class Logger 29 def initialize(bdl) 30 @bundle_name = bdl.to_s.sub(/^.*<(.*)>.*$/,'\1').split('/').last 31 @process_name = OSX::NSProcessInfo.processInfo.processName 32 end 33 34 def info(fmt, *args) 35 OSX.NSLog("#{@bundle_name} (#{@process_name}): #{fmt % args}") 36 end 37 38 def error(err) 39 info("%s: %s", err.class, err) 40 end 41 42 def backtrace(err) 43 err.backtrace.each { |s| info(" %s", s) } 44 end 45 end 46 end 47 48 def init_for_bundle(args = nil) 49 BundleSupport.init_for_bundle(args) { |*x| yield(*x) } 50 end 51 module_function :init_for_bundle 52 53end 54