Class: CocoaPodsKeys::Keyring

Inherits:
Object
  • Object
show all
Defined in:
lib/keyring.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#keysObject

Returns the value of attribute keys.



5
6
7
# File 'lib/keyring.rb', line 5

def keys
  @keys
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/keyring.rb', line 5

def name
  @name
end

#pathObject

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_prefixObject



25
26
27
# File 'lib/keyring.rb', line 25

def self.keychain_prefix
  'cocoapods-keys-'
end

Instance Method Details

#camel_cased_keysObject



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_nameObject



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

#keychainObject



29
30
31
# File 'lib/keyring.rb', line 29

def keychain
  @keychain ||= OSXKeychain.new
end

#keychain_dataObject



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

Returns:

  • (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_hashObject



17
18
19
# File 'lib/keyring.rb', line 17

def to_hash
  { 'keys' => @keys, 'path' => @path, 'name' => @name }
end