Sha256: 088a0ab395492a3ff5c79b9b6e2eb0ecfc7a014a928b44e60347c0dfc03752a3

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

require 'digest'
require 'yaml'
require 'pathname'

module CocoaPodsKeys
  class KeyringLiberator
    # Gets given a gives back a Keyring for the project
    # by basically parsing it out of ~/.cocoapods/keys/"pathMD5".yml

    def self.keys_dir
      Pathname('~/.cocoapods/keys/').expand_path
    end

    def self.yaml_path_for_path(path)
      sha = Digest::MD5.hexdigest(path.to_s)
      keys_dir + (sha + '.yml')
    end

    def self.get_keyring(path)
      get_keyring_at_path(yaml_path_for_path(path))
    end

    def self.get_keyring_named(name)
      get_all_keyrings.find { |k| k.name == name }
    end

    def self.save_keyring(keyring)
      keys_dir.mkpath

      yaml_path_for_path(keyring.path).open('w') { |f| f.write(YAML.dump(keyring.to_hash)) }
    end

    def self.get_all_keyrings
      return [] unless keys_dir.directory?
      rings = []
      Pathname.glob(keys_dir + '*.yml').each do |path|
        rings << get_keyring_at_path(path)
      end
      rings
    end

    private

    def self.get_keyring_at_path(path)
      Keyring.from_hash(YAML.load(path.read)) if path.file?
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cocoapods-keys-1.4.0 lib/keyring_liberator.rb
cocoapods-keys-1.3.2 lib/keyring_liberator.rb
cocoapods-keys-1.3.1 lib/keyring_liberator.rb
cocoapods-keys-1.3.0 lib/keyring_liberator.rb