Class: CocoaPodsKeys::Keyring
- Inherits:
-
Object
- Object
- CocoaPodsKeys::Keyring
- Defined in:
- lib/keyring.rb
Instance Attribute Summary collapse
-
#keys ⇒ Object
Returns the value of attribute keys.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #camel_cased_keys ⇒ Object
- #code_name ⇒ Object
-
#initialize(name, path, keys = []) ⇒ Keyring
constructor
A new instance of Keyring.
- #keychain ⇒ Object
- #keychain_data ⇒ Object
- #keychain_has_key?(key) ⇒ Boolean
- #keychain_value(key) ⇒ Object
- #save(key, value) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(name, path, keys = []) ⇒ Keyring
9 10 11 12 13 |
# File 'lib/keyring.rb', line 9 def initialize(name, path, keys = []) @name = name.to_s @path = path.to_s @keys = keys end |
Instance Attribute Details
#keys ⇒ Object
Returns the value of attribute keys.
7 8 9 |
# File 'lib/keyring.rb', line 7 def keys @keys end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/keyring.rb', line 7 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/keyring.rb', line 7 def path @path end |
Class Method Details
.from_hash(hash) ⇒ Object
15 16 17 |
# File 'lib/keyring.rb', line 15 def self.from_hash(hash) new(hash['name'], hash['path'], hash['keys']) end |
.keychain_prefix ⇒ Object
27 28 29 |
# File 'lib/keyring.rb', line 27 def self.keychain_prefix 'cocoapods-keys-' end |
Instance Method Details
#camel_cased_keys ⇒ Object
67 68 69 |
# 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 ⇒ Object
23 24 25 |
# 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 ⇒ Object
31 32 33 |
# File 'lib/keyring.rb', line 31 def keychain @keychain ||= Keychain.generic_passwords end |
#keychain_data ⇒ Object
45 46 47 48 49 |
# File 'lib/keyring.rb', line 45 def keychain_data Hash[ @keys.map { |key| [key, keychain_value(key)] } ] end |
#keychain_has_key?(key) ⇒ Boolean
51 52 53 54 55 56 57 58 59 60 61 |
# 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) ⇒ Object
63 64 65 |
# 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) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# 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_has_keykeychain.create(service: self.class.keychain_prefix + name, password: value, account: key) end end |
#to_hash ⇒ Object
19 20 21 |
# File 'lib/keyring.rb', line 19 def to_hash { 'keys' => @keys, 'path' => @path, 'name' => @name } end |