Class: Keytaker::Item
- Inherits:
-
Object
- Object
- Keytaker::Item
- Defined in:
- lib/keytaker/item.rb
Constant Summary collapse
- SERVICE_NAME =
'ruby-keytaker'
Class Method Summary collapse
Instance Method Summary collapse
- #copy ⇒ Object
- #delete ⇒ Object
-
#initialize(item) ⇒ Item
constructor
A new instance of Item.
- #update(value:) ⇒ Object
Constructor Details
#initialize(item) ⇒ Item
Returns a new instance of Item.
29 30 31 |
# File 'lib/keytaker/item.rb', line 29 def initialize(item) @item = item end |
Class Method Details
.create(key:, value:) ⇒ Object
24 25 26 |
# File 'lib/keytaker/item.rb', line 24 def create(key:, value:) Keychain.generic_passwords.create(service: SERVICE_NAME, account: key, password: value) end |
.find(key) ⇒ Object
9 10 11 12 |
# File 'lib/keytaker/item.rb', line 9 def find(key) item = Keychain.generic_passwords.where(service: SERVICE_NAME, account: key).first item ? new(item) : nil end |
.select ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/keytaker/item.rb', line 14 def select accounts = Keychain.generic_passwords.where(service: SERVICE_NAME).all.map(&:account) if accounts.empty? nil else key, _ = *PecoSelector.select_from(accounts) Keytaker::Item.find(key) end end |
Instance Method Details
#copy ⇒ Object
33 34 35 36 37 |
# File 'lib/keytaker/item.rb', line 33 def copy IO.popen('pbcopy', 'w') do |f| f << @item.password end end |
#delete ⇒ Object
44 45 46 |
# File 'lib/keytaker/item.rb', line 44 def delete @item.delete end |
#update(value:) ⇒ Object
39 40 41 42 |
# File 'lib/keytaker/item.rb', line 39 def update(value:) @item.password = value @item.save! end |