Sha256: a6aa0a604fad8cdcfd047d9f1251e526439126fa117c26e559e86866c5b86cf1

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

require 'hackmac/plist'
require 'pathname'
require 'tins/string_version'

module Hackmac
  class Kext
    include Hackmac::Plist
    include Tins::StringVersion

    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

    attr_reader :path

    def identifier
      CFBundleIdentifier()
    end

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

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

    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

    def remote_version
      remote_kext&.version
    end

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hackmac-0.5.0 lib/hackmac/kext.rb
hackmac-0.4.2 lib/hackmac/kext.rb
hackmac-0.4.1 lib/hackmac/kext.rb
hackmac-0.4.0 lib/hackmac/kext.rb
hackmac-0.3.4 lib/hackmac/kext.rb