class Rubyists::Opr::Item

An item

Attributes

name[R]
raw[R]
uuid[R]

Public Class Methods

create(hash, title, vault = 'Private', type: :login) click to toggle source
# File lib/rubyists::opr/model/item.rb, line 13
def self.create(hash, title, vault = 'Private', type: :login)
  cmd = TTY::Command.new pty: true, printer: :null
  
  Opr.with_login do
    cmd.run "#{Opr.opbin} create item '#{type.capitalize}' '#{hash}' --vault='#{vault}' --title='#{title}'"
  end
end
find(item, vault:) click to toggle source
# File lib/rubyists::opr/model/item.rb, line 21
def self.find(item, vault:)
  cmd = TTY::Command.new pty: true, printer: :null
  out, err = Opr.with_login do
    cmd.run "#{Opr.opbin} get item '#{item}' --vault='#{vault}'"
  end
  raise Error, err unless err.empty?

  from_output out
rescue TTY::Command::ExitError => e
  return nil if e.to_s.match? /item with query "#{Regexp.escape(item)}" not found/

  raise
end
from_hash(hash) click to toggle source
# File lib/rubyists::opr/model/item.rb, line 9
def self.from_hash(hash)
  new uuid: hash['uuid'], name: hash['overview']['title'], raw: hash
end
from_output(string) click to toggle source
# File lib/rubyists::opr/model/item.rb, line 5
def self.from_output(string)
  from_hash JSON.parse(string)
end
new(uuid:, name:, raw:) click to toggle source
# File lib/rubyists::opr/model/item.rb, line 36
def initialize(uuid:, name:, raw:)
  @name = name
  @uuid = uuid
  @raw  = raw
end

Public Instance Methods

delete!() click to toggle source
# File lib/rubyists::opr/model/item.rb, line 46
def delete!
  Opr.with_login do
    cmd = TTY::Command.new pty: true, printer: :null
    cmd.run "#{Opr.opbin} delete item '#{name}' --vault='#{vault_uuid}'"
  end
end
inspect() click to toggle source
# File lib/rubyists::opr/model/item.rb, line 62
def inspect
  "<#{self.class}:#{object_id} name: #{name} uuid: #{uuid}>"
end
password() click to toggle source
# File lib/rubyists::opr/model/item.rb, line 53
def password
  pass_field = @raw['details']['fields'].detect { |f| f['designation'] == 'password' }
  pass_field['value']
end
title() click to toggle source
# File lib/rubyists::opr/model/item.rb, line 58
def title
  @title ||= raw['overview']['title']
end
vault_uuid() click to toggle source
# File lib/rubyists::opr/model/item.rb, line 42
def vault_uuid
  @vault_uuid ||= raw['vaultUuid']
end