Class: CreateBundle::Base
- Inherits:
-
Object
- Object
- CreateBundle::Base
- Defined in:
- lib/create_bundle.rb
Instance Attribute Summary collapse
-
#app_path ⇒ Object
Returns the value of attribute app_path.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#target_path ⇒ Object
Returns the value of attribute target_path.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #contents_dir ⇒ Object
- #copy_icon ⇒ Object
- #copy_script ⇒ Object
- #create ⇒ Object
- #create_dir(path) ⇒ Object
- #create_dirs ⇒ Object
- #create_exec ⇒ Object
- #create_plist ⇒ Object
- #custom_icon_path ⇒ Object
- #exit_and_cleanup ⇒ Object
- #icon_file ⇒ Object
- #icon_path ⇒ Object
-
#initialize(options) ⇒ Base
constructor
A new instance of Base.
- #macos_dir ⇒ Object
- #plist ⇒ Object
- #plist_path ⇒ Object
- #resources_dir ⇒ Object
- #write_script ⇒ Object
Constructor Details
#initialize(options) ⇒ Base
Returns a new instance of Base.
14 15 16 17 18 19 20 21 |
# File 'lib/create_bundle.rb', line 14 def initialize() @logger = Logger.new(STDOUT) @app_path = Pathname([:source]) @custom_icon = [:icon] @custom_script = [:script] [:target] = [:source] if [:bare] @target_path = [:target] ? Pathname([:target]) : Pathname(@app_path.basename.to_s) end |
Instance Attribute Details
#app_path ⇒ Object
Returns the value of attribute app_path.
12 13 14 |
# File 'lib/create_bundle.rb', line 12 def app_path @app_path end |
#logger ⇒ Object
Returns the value of attribute logger.
12 13 14 |
# File 'lib/create_bundle.rb', line 12 def logger @logger end |
#target_path ⇒ Object
Returns the value of attribute target_path.
12 13 14 |
# File 'lib/create_bundle.rb', line 12 def target_path @target_path end |
#verbose ⇒ Object
Returns the value of attribute verbose.
12 13 14 |
# File 'lib/create_bundle.rb', line 12 def verbose @verbose end |
Instance Method Details
#contents_dir ⇒ Object
54 55 56 |
# File 'lib/create_bundle.rb', line 54 def contents_dir target_path + 'Contents' end |
#copy_icon ⇒ Object
86 87 88 89 |
# File 'lib/create_bundle.rb', line 86 def copy_icon File.link(icon_path, resources_dir + 'applet.icns') logger.debug "Copied icon to: #{(resources_dir + 'applet.icns')}" if verbose end |
#copy_script ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/create_bundle.rb', line 98 def copy_script return false unless @custom_script if Pathname(@custom_script).exist? File.link(Pathname(@custom_script), macos_dir + 'applet') true else puts "Script file doesn't exist" exit_and_cleanup end end |
#create ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/create_bundle.rb', line 114 def create create_dirs copy_icon create_exec create_plist rescue Errno::EEXIST => e logger.error e. end |
#create_dir(path) ⇒ Object
70 71 72 73 |
# File 'lib/create_bundle.rb', line 70 def create_dir(path) Dir.mkdir path logger.debug "Created dir: #{path}" if verbose end |
#create_dirs ⇒ Object
66 67 68 |
# File 'lib/create_bundle.rb', line 66 def create_dirs [target_path, contents_dir, resources_dir, macos_dir].each { |dir| create_dir(dir) } end |
#create_exec ⇒ Object
109 110 111 112 |
# File 'lib/create_bundle.rb', line 109 def create_exec copy_script || write_script FileUtils.chmod 0o755, macos_dir + 'applet' end |
#create_plist ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/create_bundle.rb', line 75 def create_plist target_plist_hash = { 'CFBundleExecutable' => 'applet', 'CFBundleIconFile' => 'applet' } f = File.new(contents_dir + 'Info.plist', 'w') f.puts target_plist_hash.to_plist f.close logger.debug "Created plist file: #{(contents_dir + 'Info.plist')}" if verbose end |
#custom_icon_path ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/create_bundle.rb', line 23 def custom_icon_path return false unless @custom_icon if Pathname(@custom_icon).exist? Pathname(@custom_icon) else puts "Icon file doesn't exist" exit_and_cleanup end end |
#exit_and_cleanup ⇒ Object
123 124 125 126 |
# File 'lib/create_bundle.rb', line 123 def exit_and_cleanup FileUtils.rm_rf(target_path) exit end |
#icon_file ⇒ Object
50 51 52 |
# File 'lib/create_bundle.rb', line 50 def icon_file !/icns$/.match?(plist['CFBundleIconFile']) ? plist['CFBundleIconFile'] + '.icns' : plist['CFBundleIconFile'] end |
#icon_path ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/create_bundle.rb', line 33 def icon_path custom_icon_path || app_path + 'Contents' + 'Resources' + icon_file rescue ArgumentError logger.warn 'Problem reading source plist file, probably binary format, falling back to default icon name' icon = app_path + 'Contents' + 'Resources' + 'AppIcon.icns' icon || exit_and_cleanup end |
#macos_dir ⇒ Object
62 63 64 |
# File 'lib/create_bundle.rb', line 62 def macos_dir contents_dir + 'MacOS' end |
#plist ⇒ Object
46 47 48 |
# File 'lib/create_bundle.rb', line 46 def plist Plist.parse_xml(plist_path) end |
#plist_path ⇒ Object
41 42 43 44 |
# File 'lib/create_bundle.rb', line 41 def plist_path path = app_path + 'Contents' + 'Info.plist' path.exist? ? path : (logger.info("Source doesn't look like an app bundle") && exit) end |
#resources_dir ⇒ Object
58 59 60 |
# File 'lib/create_bundle.rb', line 58 def resources_dir contents_dir + 'Resources' end |
#write_script ⇒ Object
91 92 93 94 95 96 |
# File 'lib/create_bundle.rb', line 91 def write_script f = File.new(macos_dir + 'applet', 'w') f.puts "#!/bin/sh\nopen -a \"#{ARGV[0]}\"" f.close logger.debug "Created exec: #{(macos_dir + 'applet')}" if verbose end |