lib/keyring.rb in cocoapods-keys-1.4.0 vs lib/keyring.rb in cocoapods-keys-1.5.0
- old
+ new
@@ -4,11 +4,11 @@
class Keyring
attr_accessor :keys, :path, :name
def initialize(name, path, keys = [])
@name = name.to_s
- @path = path
+ @path = path.to_s
@keys = keys
end
def self.from_hash(hash)
new(hash['name'], hash['path'], hash['keys'])
@@ -24,19 +24,37 @@
def self.keychain_prefix
'cocoapods-keys-'
end
+ def keychain
+ @keychain ||= OSXKeychain.new
+ end
+
def save(key, value)
- keychain = OSXKeychain.new
keychain[self.class.keychain_prefix + name, key] = value
end
def keychain_data
- keychain = OSXKeychain.new
Hash[
- @keys.map { |key| [key, ENV[key] || keychain[self.class.keychain_prefix + name, key]] }
+ @keys.map { |key| [key, keychain_value(key)] }
]
+ end
+
+ def keychain_has_key?(key)
+ has_key = !keychain_value(key).nil?
+
+ if has_key && !@keys.include?(key)
+ @keys << key
+ elsif !has_key && @keys.include?(key)
+ @keys.delete(key)
+ end
+
+ has_key
+ end
+
+ def keychain_value(key)
+ ENV[key] || keychain[self.class.keychain_prefix + name, key]
end
def camel_cased_keys
Hash[keychain_data.map { |(key, value)| [key[0].downcase + key[1..-1], value] }]
end