Class: Hackmac::Kext

Inherits:
Object
  • Object
show all
Includes:
Plist, Tins::StringVersion
Defined in:
lib/hackmac/kext.rb

Instance Method Summary collapse

Methods included from Plist

#as_hash, #method_missing, #plist, #to_json

Constructor Details

#initialize(path:, config: nil) ⇒ Kext

Returns a new instance of Kext.



10
11
12
13
14
# File 'lib/hackmac/kext.rb', line 10

def initialize(path:, config: nil)
  @path   = Pathname.new(path) + 'Contents/Info.plist'
  @plist  = File.open(@path, encoding: 'UTF-8') { |f| ::Plist.parse_xml(f) }
  @config = config
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hackmac::Plist

Instance Method Details

#identifierObject



16
17
18
# File 'lib/hackmac/kext.rb', line 16

def identifier
  CFBundleIdentifier()
end

#inspectObject



51
52
53
# File 'lib/hackmac/kext.rb', line 51

def inspect
  "#<#{self.class}: #{to_s}>"
end

#nameObject



20
21
22
# File 'lib/hackmac/kext.rb', line 20

def name
  CFBundleName() || File.basename(identifier)
end

#remote_kextObject



37
38
39
40
41
42
43
44
45
# File 'lib/hackmac/kext.rb', line 37

def remote_kext
  if @config
    if github = @config.kext.sources[name]&.github
      auth = [ @config.github.user, @config.github.access_token ].compact
      auth.empty? and auth = nil
      @remote_kext = Hackmac::KextSource.new(github, auth: auth)
    end
  end
end

#remote_versionObject



47
48
49
# File 'lib/hackmac/kext.rb', line 47

def remote_version
  remote_kext&.version
end

#to_sObject



55
56
57
# File 'lib/hackmac/kext.rb', line 55

def to_s
  "#{name} #{version}"
end

#versionObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hackmac/kext.rb', line 24

def version
  unless @version
    if version = CFBundleShortVersionString()
      begin
        @version = Version.new(version)
      rescue ArgumentError
        @version = version
      end
    end
  end
  @version
end