Class: RunLoop::App

Inherits:
Object
  • Object
show all
Defined in:
lib/run_loop/app.rb

Overview

A class for interacting with .app bundles.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_bundle_path) ⇒ RunLoop::App

Note:

The ‘app_bundle_path` is expanded during initialization.

Creates a new App instance.

Parameters:

  • app_bundle_path (String)

    A path to a .app



15
16
17
# File 'lib/run_loop/app.rb', line 15

def initialize(app_bundle_path)
  @path = File.expand_path(app_bundle_path)
end

Instance Attribute Details

#pathString (readonly)

Returns The path to the app bundle .app.

Returns:

  • (String)

    The path to the app bundle .app



7
8
9
# File 'lib/run_loop/app.rb', line 7

def path
  @path
end

Instance Method Details

#bundle_identifierString

Inspects the app’s Info.plist for the bundle identifier.

Returns:

  • (String)

    The value of CFBundleIdentifier.

Raises:

  • (RuntimeError)

    If the plist cannot be read or the CFBundleIdentifier is empty or does not exist.



40
41
42
43
44
45
46
# File 'lib/run_loop/app.rb', line 40

def bundle_identifier
  identifier = plist_buddy.plist_read('CFBundleIdentifier', info_plist_path)
  unless identifier
    raise "Expected key 'CFBundleIdentifier' in '#{info_plist_path}'"
  end
  identifier
end

#executable_nameString

Inspects the app’s Info.plist for the executable name.

Returns:

  • (String)

    The value of CFBundleIdentifier.

Raises:

  • (RuntimeError)

    If the plist cannot be read or the CFBundleExecutable is empty or does not exist.



52
53
54
55
56
57
58
# File 'lib/run_loop/app.rb', line 52

def executable_name
  identifier = plist_buddy.plist_read('CFBundleExecutable', info_plist_path)
  unless identifier
    raise "Expected key 'CFBundleExecutable' in '#{info_plist_path}'"
  end
  identifier
end

#info_plist_pathObject

Returns the Info.plist path.

Raises:

  • (RuntimeError)

    If there is no Info.plist.



28
29
30
31
32
33
34
# File 'lib/run_loop/app.rb', line 28

def info_plist_path
  info_plist = File.join(path, 'Info.plist')
  unless File.exist?(info_plist)
    raise "Expected an Info.plist at '#{path}'"
  end
  info_plist
end

#valid?Boolean

Is this a valid app?

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/run_loop/app.rb', line 20

def valid?
  [File.exist?(path),
   File.directory?(path),
   File.extname(path) == '.app'].all?
end