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(path, target_path = nil, custom_script = nil, custom_icon = nil, bare = false) ⇒ Base
constructor
A new instance of Base.
- #macos_dir ⇒ Object
- #plist ⇒ Object
- #plist_path ⇒ Object
- #resources_dir ⇒ Object
- #write_script ⇒ Object
Constructor Details
#initialize(path, target_path = nil, custom_script = nil, custom_icon = nil, bare = false) ⇒ Base
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/create_bundle.rb', line 14 def initialize(path, target_path = nil, custom_script = nil, custom_icon = nil, = false) @logger = Logger.new(STDOUT) @app_path = Pathname(path) @custom_icon = custom_icon @custom_script = custom_script if target_path = path else (logger.info("Source doesn't look like an app bundle") && exit) unless plist_path.exist? end @target_path = target_path ? Pathname(target_path) : 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
57 58 59 |
# File 'lib/create_bundle.rb', line 57 def contents_dir target_path + 'Contents' end |
#copy_icon ⇒ Object
89 90 91 92 |
# File 'lib/create_bundle.rb', line 89 def copy_icon File.link(custom_icon_path || icon_path, resources_dir + 'applet.icns') logger.debug "Copied icon to: #{(resources_dir + 'applet.icns')}" if verbose end |
#copy_script ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/create_bundle.rb', line 102 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
117 118 119 120 121 122 123 124 |
# File 'lib/create_bundle.rb', line 117 def create create_dirs copy_icon create_exec create_plist rescue Errno::EEXIST => e logger.error e. end |
#create_dir(path) ⇒ Object
73 74 75 76 |
# File 'lib/create_bundle.rb', line 73 def create_dir(path) Dir.mkdir path logger.debug "Created dir: #{path}" if verbose end |
#create_dirs ⇒ Object
69 70 71 |
# File 'lib/create_bundle.rb', line 69 def create_dirs [target_path, contents_dir, resources_dir, macos_dir].each { |dir| create_dir(dir) } end |
#create_exec ⇒ Object
113 114 115 |
# File 'lib/create_bundle.rb', line 113 def create_exec copy_script || write_script end |
#create_plist ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/create_bundle.rb', line 78 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
27 28 29 30 31 32 33 34 35 |
# File 'lib/create_bundle.rb', line 27 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
126 127 128 129 |
# File 'lib/create_bundle.rb', line 126 def exit_and_cleanup FileUtils.rm_rf(target_path) exit end |
#icon_file ⇒ Object
53 54 55 |
# File 'lib/create_bundle.rb', line 53 def icon_file !/icns$/.match?(plist['CFBundleIconFile']) ? plist['CFBundleIconFile'] + '.icns' : plist['CFBundleIconFile'] end |
#icon_path ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/create_bundle.rb', line 37 def 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
65 66 67 |
# File 'lib/create_bundle.rb', line 65 def macos_dir contents_dir + 'MacOS' end |
#plist ⇒ Object
49 50 51 |
# File 'lib/create_bundle.rb', line 49 def plist Plist.parse_xml(plist_path) end |
#plist_path ⇒ Object
45 46 47 |
# File 'lib/create_bundle.rb', line 45 def plist_path app_path + 'Contents' + 'Info.plist' end |
#resources_dir ⇒ Object
61 62 63 |
# File 'lib/create_bundle.rb', line 61 def resources_dir contents_dir + 'Resources' end |
#write_script ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/create_bundle.rb', line 94 def write_script f = File.new(macos_dir + 'applet', 'w') f.puts "#!/bin/sh\nopen -a \"#{ARGV[0]}\"" f.close FileUtils.chmod 0o755, macos_dir + 'applet' logger.debug "Created exec: #{(macos_dir + 'applet')}" if verbose end |