Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Created November 1, 2011 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveitaly/1331293 to your computer and use it in GitHub Desktop.
Save iloveitaly/1331293 to your computer and use it in GitHub Desktop.
MacRuby Snippets
def crash_log_path
app_name = NSBundle.mainBundle.infoDictionary.objectForKey "CFBundleExecutable"
crash_file_list = []
fm = NSFileManager.defaultManager
past_date = NSDate.dateWithTimeIntervalSinceNow -(60 * 60 * 24 * 7)
crash_log_dir = File.join NSHomeDirectory(), "Library/Logs/CrashReporter"
begin
Find.find(crash_log_dir) do |crash_file|
if not crash_file == crash_log_dir and FileTest.directory? crash_file
Find.prune
next
elsif crash_file == crash_log_dir
next
end
# $log.debug "Found possible log file: " + crash_file
if File.basename(crash_file).start_with? app_name + "_" and crash_file.end_with? ".crash"
last_modified = fm.attributesOfItemAtPath(crash_file, error: nil)["NSFileModificationDate"]
if last_modified.isGreaterThan past_date
crash_file_list << crash_file
else
$log.debug "Crash log (%s) is more than a week old. Trashing it." % crash_file
FileUtils.rm crash_file
end
end
end
rescue Exception => e
$log.error "Error searching crash directory #{e}"
return ""
end
return "" if crash_file_list.length == 0
crash_file_list.sort!
crash_file_list.pop
end
# Enable garbage collection support, which MacRuby requires.
post_install do |installer|
installer.project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['GCC_ENABLE_OBJC_GC'] = 'supported'
end
end
end
generate_bridge_support!
# Loading the Cocoa framework. If you need to load more frameworks, you can
# do that here too.
framework 'Cocoa'
# Loading all the Ruby project files.
# manual load allows up to specify the load order for some of the classes
# this is needed for situations when one of your ruby classes is a subclass of another ruby class that hasn't yet been loaded
# note that this bug may only show its face in deployment and your application may work fine in development
manualLoad = ["ClassToLoadFirst"]
for file in manualLoad
puts "Loading: " + file
require file
end
manualLoad << File.basename(__FILE__, File.extname(__FILE__))
# Auto load the direct of the files in the dir
dir_path = NSBundle.mainBundle.resourcePath
Dir.glob(File.join(dir_path, '*.{rb,rbo}')).map { |x| File.basename(x, File.extname(x)) }.uniq.each do |path|
if not manualLoad.include? path
puts "Loading: " + path
require(path)
end
end
# Starting the Cocoa main loop.
NSApplicationMain(0, nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment