Class: Boom::Storage::Keychain
- Defined in:
- lib/kaboom/storage/keychain.rb
Constant Summary collapse
- KEYCHAIN_FORMAT =
%r{Boom\.list\.(.+)\.keychain}
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#bootstrap ⇒ Object
Boostraps Keychain by checking if you’re using a Mac which is a prereq.
-
#is_mac? ⇒ Boolean
Asks if you’re using Mac OS X.
-
#open_keychain_app ⇒ Object
(also: #json_file)
Opens Keychain app when json_file is called during ‘boom edit`.
-
#populate ⇒ Object
Populate the in-memory store with all the lists and items from Keychain.
-
#save ⇒ Object
Saves the data from memory to the correct Keychain.
Methods inherited from Base
#handle, #initialize, #item_exists?, #items, #list_exists?, #to_hash
Constructor Details
This class inherits a constructor from Boom::Storage::Base
Instance Method Details
#bootstrap ⇒ Object
Boostraps Keychain by checking if you’re using a Mac which is a prereq
Returns
25 26 27 28 29 30 |
# File 'lib/kaboom/storage/keychain.rb', line 25 def bootstrap raise RuntimeError unless is_mac? rescue puts('No Keychain utility to access, maybe try another storage option?') exit end |
#is_mac? ⇒ Boolean
Asks if you’re using Mac OS X
Returns true on a Mac
35 36 37 |
# File 'lib/kaboom/storage/keychain.rb', line 35 def is_mac? return Boom::Platform.darwin? end |
#open_keychain_app ⇒ Object Also known as: json_file
Opens Keychain app when json_file is called during ‘boom edit`
Returns nothing
16 17 18 |
# File 'lib/kaboom/storage/keychain.rb', line 16 def open_keychain_app `open /Applications/Utilities/'Keychain Access.app' &` end |
#populate ⇒ Object
Populate the in-memory store with all the lists and items from Keychain
Returns Array of keychain names, i.e. [“Boom.list.mylist.keychain”]
42 43 44 45 46 47 48 49 |
# File 'lib/kaboom/storage/keychain.rb', line 42 def populate stored_keychain_lists.each do |keychain| @lists << list = List.new(keychain.scan(KEYCHAIN_FORMAT).flatten.first) extract_keychain_items(keychain).each do |name| list.add_item(Item.new(name, extract_keychain_value(name, keychain))) end end end |
#save ⇒ Object
Saves the data from memory to the correct Keychain
Returns nothing
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/kaboom/storage/keychain.rb', line 54 def save @lists.each do |list| keychain_name = list_to_filename(list.name) create_keychain_list(keychain_name) unless stored_keychain_lists.include?(keychain_name) unless list.items.empty? list.items.each do |item| store_item(item, keychain_name) end end delete_unwanted_items(list) end delete_unwanted_lists rescue RuntimeError puts(e "Couldn't save to your keychain, check Console.app or above for relevant messages") end |