class OnePassword::Item
Constants
- INDEX_DATE
- INDEX_FOLDER
- INDEX_NAME
- INDEX_PASSWORD_STRENGTH
- INDEX_TRASHED
- INDEX_TYPE
- INDEX_URL
- INDEX_UUID
Attributes
domain[RW]
@return [String]
encrypted[RW]
@return [String]
open_contents[RW]
@return [String]
profile[R]
@return [OnePassword::Profile]
security_level[RW]
@return [String]
title[RW]
@return [String]
trashed[RW]
@return [String]
type[RW]
@return [String]
updated_at[RW]
@return [String]
uuid[RW]
@return [String]
Public Class Methods
new(profile, data)
click to toggle source
@param [Profile] profile @param [Array] data
# File lib/one_password/item.rb, line 34 def initialize(profile, data) @profile = profile self.attributes = { uuid: data[INDEX_UUID], type: data[INDEX_TYPE], title: data[INDEX_NAME], domain: data[INDEX_URL], updated_at: data[INDEX_DATE], trashed: data[INDEX_TRASHED] } end
Public Instance Methods
attributes()
click to toggle source
# File lib/one_password/item.rb, line 132 def attributes @attributes ||= {} fields = instance_variables.inject({}) do |result, ivar| result[ivar] = instance_variable_get(ivar) unless ivar == :@profile result end @attributes.merge(fields) end
attributes=(attrs)
click to toggle source
# File lib/one_password/item.rb, line 141 def attributes=(attrs) attrs.each do |name, value| if value.present? attribute = name.to_s.underscore writer = "#{attribute}=" if respond_to?(writer) send(writer, value) else @attributes ||= {} @attributes[attribute] = value end end end end
category()
click to toggle source
# File lib/one_password/item.rb, line 66 def category @category ||= case type when SOFTWARE_LICENSES, WEBFORMS, NOTES, IDENTITIES, PASSWORDS type.to_sym else if type == FOLDERS :folders elsif wallet? WALLET else ACCOUNT.to_sym end end end
created_at=(seconds)
click to toggle source
# File lib/one_password/item.rb, line 50 def created_at=(seconds) @created_at = Time.at(seconds) end
decrypt_data()
click to toggle source
# File lib/one_password/item.rb, line 106 def decrypt_data unless @decrypted @decrypted = true plain_text = Encryption.decrypt_using_key(encrypted, encryption_key) attrs = JSON.parse(plain_text) self.attributes = attrs end end
encryption_key()
click to toggle source
# File lib/one_password/item.rb, line 93 def encryption_key profile.encryption_keys[security_level].decrypted_key end
file_name()
click to toggle source
# File lib/one_password/item.rb, line 85 def file_name profile.directory.join("#{uuid}.1password") end
find_field_with_designation(designation)
click to toggle source
# File lib/one_password/item.rb, line 123 def find_field_with_designation(designation) fields = attributes['fields'] field = fields.find do |field| field['designation'] == designation end if fields field['value'] if field end
load_encrypted_data()
click to toggle source
# File lib/one_password/item.rb, line 97 def load_encrypted_data self.attributes = JSON.parse(File.read(file_name)) end
login_password()
click to toggle source
# File lib/one_password/item.rb, line 119 def login_password attributes['password'].presence || find_field_with_designation('password') end
login_username()
click to toggle source
# File lib/one_password/item.rb, line 115 def login_username find_field_with_designation('username') end
matches?(text)
click to toggle source
# File lib/one_password/item.rb, line 81 def matches?(text) title.downcase.index(text) || domain.downcase.index(text) end
system?()
click to toggle source
# File lib/one_password/item.rb, line 54 def system? @type =~ /^system/ end
trashed?()
click to toggle source
# File lib/one_password/item.rb, line 62 def trashed? @trashed == 'Y' end
updated_at=(seconds)
click to toggle source
# File lib/one_password/item.rb, line 46 def updated_at=(seconds) @updated_at = Time.at(seconds) end
wallet?()
click to toggle source
# File lib/one_password/item.rb, line 58 def wallet? @type =~ /^wallet\.(membership|financial|government)}/ end