class CocoaPodsKeys::Keyring
Attributes
keys[RW]
name[RW]
path[RW]
Public Class Methods
from_hash(hash)
click to toggle source
# File lib/keyring.rb, line 15 def self.from_hash(hash) new(hash['name'], hash['path'], hash['keys']) end
keychain_prefix()
click to toggle source
# File lib/keyring.rb, line 27 def self.keychain_prefix 'cocoapods-keys-' end
new(name, path, keys = [])
click to toggle source
# File lib/keyring.rb, line 9 def initialize(name, path, keys = []) @name = name.to_s @path = path.to_s @keys = keys end
Public Instance Methods
camel_cased_keys()
click to toggle source
# File lib/keyring.rb, line 67 def camel_cased_keys Hash[keychain_data.map { |(key, value)| [key[0].downcase + key[1..-1], value] }] end
code_name()
click to toggle source
# File lib/keyring.rb, line 23 def code_name name.split(/[^a-zA-Z0-9_]/).map { |s| s[0].upcase + s[1..-1] }.join('') end
keychain()
click to toggle source
# File lib/keyring.rb, line 31 def keychain @keychain ||= Keychain.generic_passwords end
keychain_data()
click to toggle source
# File lib/keyring.rb, line 45 def keychain_data Hash[ @keys.map { |key| [key, keychain_value(key)] } ] end
keychain_has_key?(key)
click to toggle source
# File lib/keyring.rb, line 51 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
keychain_value(key)
click to toggle source
# File lib/keyring.rb, line 63 def keychain_value(key) ENV[key] || keychain.where(service: self.class.keychain_prefix + name, account: key).first&.password end
save(key, value)
click to toggle source
# File lib/keyring.rb, line 35 def save(key, value) item = keychain.where(service: self.class.keychain_prefix + name, account: key).first if item item.password = value item.save! else keychain.create(service: self.class.keychain_prefix + name, password: value, account: key) end end
to_hash()
click to toggle source
# File lib/keyring.rb, line 19 def to_hash { 'keys' => @keys, 'path' => @path, 'name' => @name } end