Class: DesignShell::KeyChain

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

Instance Method Summary collapse

Constructor Details

#initialize(aNamespace) ⇒ KeyChain

Returns a new instance of KeyChain.



4
5
6
7
# File 'lib/designshell/key_chain.rb', line 4

def initialize(aNamespace)
  @keychain = OSXKeychain.new
  @namespace = aNamespace
end

Instance Method Details

#[](aKey) ⇒ Object



9
10
11
# File 'lib/designshell/key_chain.rb', line 9

def [](aKey)
  get(aKey)
end

#[]=(aKey, aValue) ⇒ Object



13
14
15
# File 'lib/designshell/key_chain.rb', line 13

def []=(aKey,aValue)
  set(aKey,aValue)
end

#get(aKey, aPrefix = nil, aKeepPrefix = false) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/designshell/key_chain.rb', line 26

def get(aKey,aPrefix=nil,aKeepPrefix=false)
  if (aKey.is_a?(Array))
    result = {}
    aKey.each do |k|
      storeKey = (aKeepPrefix ? aPrefix.to_s+k.to_s : k.to_s)
      v = get(k.to_s,aPrefix)
      result[storeKey] = v
    end
    return result
  else
    return @keychain[@namespace,aPrefix.to_s+aKey.to_s]
  end
end

#set(aKey, aValue = nil, aPrefix = '') ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/designshell/key_chain.rb', line 17

def set(aKey,aValue=nil,aPrefix='')
  if (aKey.is_a?(String) || aKey.is_a?(Symbol))
    @keychain[@namespace,aPrefix.to_s+aKey.to_s] = aValue
  elsif aKey.is_a?(Hash)
    prefix = aValue || aPrefix
    aKey.each {|k,v| set(k,v,prefix)}
  end
end