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
Returns a new instance of Keyring.
7 8 9 10 11 |
# File 'lib/keyring.rb', line 7 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.
5 6 7 |
# File 'lib/keyring.rb', line 5 def keys @keys end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/keyring.rb', line 5 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/keyring.rb', line 5 def path @path end |
Class Method Details
.from_hash(hash) ⇒ Object
13 14 15 |
# File 'lib/keyring.rb', line 13 def self.from_hash(hash) new(hash['name'], hash['path'], hash['keys']) end |
.keychain_prefix ⇒ Object
25 26 27 |
# File 'lib/keyring.rb', line 25 def self.keychain_prefix 'cocoapods-keys-' end |
Instance Method Details
#camel_cased_keys ⇒ Object
59 60 61 |
# File 'lib/keyring.rb', line 59 def camel_cased_keys Hash[keychain_data.map { |(key, value)| [key[0].downcase + key[1..-1], value] }] end |
#code_name ⇒ Object
21 22 23 |
# File 'lib/keyring.rb', line 21 def code_name name.split(/[^a-zA-Z0-9_]/).map { |s| s[0].upcase + s[1..-1] }.join('') end |
#keychain ⇒ Object
29 30 31 |
# File 'lib/keyring.rb', line 29 def keychain @keychain ||= OSXKeychain.new end |
#keychain_data ⇒ Object
37 38 39 40 41 |
# File 'lib/keyring.rb', line 37 def keychain_data Hash[ @keys.map { |key| [key, keychain_value(key)] } ] end |
#keychain_has_key?(key) ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/keyring.rb', line 43 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
55 56 57 |
# File 'lib/keyring.rb', line 55 def keychain_value(key) ENV[key] || keychain[self.class.keychain_prefix + name, key] end |
#save(key, value) ⇒ Object
33 34 35 |
# File 'lib/keyring.rb', line 33 def save(key, value) keychain[self.class.keychain_prefix + name, key] = value end |
#to_hash ⇒ Object
17 18 19 |
# File 'lib/keyring.rb', line 17 def to_hash { 'keys' => @keys, 'path' => @path, 'name' => @name } end |