Class: Hackmac::Kext

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

Instance Attribute Summary collapse

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
15
# File 'lib/hackmac/kext.rb', line 10

def initialize(path:, config: nil)
  @path   = path
  info    = Pathname.new(@path) + 'Contents/Info.plist'
  @plist  = File.open(info, 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 Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#identifierObject



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

def identifier
  CFBundleIdentifier()
end

#inspectObject



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

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

#nameObject



23
24
25
# File 'lib/hackmac/kext.rb', line 23

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

#remote_kextObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/hackmac/kext.rb', line 40

def remote_kext
  return @remote_kext if @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



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

def remote_version
  remote_kext&.version
end

#to_sObject



59
60
61
# File 'lib/hackmac/kext.rb', line 59

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

#versionObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hackmac/kext.rb', line 27

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