Class: Rubyists::Opr::Item
- Inherits:
-
Object
- Object
- Rubyists::Opr::Item
- Defined in:
- lib/rubyists::opr/model/item.rb
Overview
An item
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
- .create(hash, title, vault = 'Private', type: :login) ⇒ Object
- .find(item, vault:) ⇒ Object
- .from_hash(hash) ⇒ Object
- .from_output(string) ⇒ Object
Instance Method Summary collapse
- #delete! ⇒ Object
-
#initialize(uuid:, name:, raw:) ⇒ Item
constructor
A new instance of Item.
- #inspect ⇒ Object
- #password ⇒ Object
- #title ⇒ Object
- #vault_uuid ⇒ Object
Constructor Details
#initialize(uuid:, name:, raw:) ⇒ Item
Returns a new instance of Item.
36 37 38 39 40 |
# File 'lib/rubyists::opr/model/item.rb', line 36 def initialize(uuid:, name:, raw:) @name = name @uuid = uuid @raw = raw end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
35 36 37 |
# File 'lib/rubyists::opr/model/item.rb', line 35 def name @name end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
35 36 37 |
# File 'lib/rubyists::opr/model/item.rb', line 35 def raw @raw end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
35 36 37 |
# File 'lib/rubyists::opr/model/item.rb', line 35 def uuid @uuid end |
Class Method Details
.create(hash, title, vault = 'Private', type: :login) ⇒ Object
13 14 15 16 17 18 19 |
# 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:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
9 10 11 |
# 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) ⇒ Object
5 6 7 |
# File 'lib/rubyists::opr/model/item.rb', line 5 def self.from_output(string) from_hash JSON.parse(string) end |
Instance Method Details
#delete! ⇒ Object
46 47 48 49 50 51 |
# 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 ⇒ Object
62 63 64 |
# File 'lib/rubyists::opr/model/item.rb', line 62 def inspect "<#{self.class}:#{object_id} name: #{name} uuid: #{uuid}>" end |
#password ⇒ Object
53 54 55 56 |
# 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 ⇒ Object
58 59 60 |
# File 'lib/rubyists::opr/model/item.rb', line 58 def title @title ||= raw['overview']['title'] end |
#vault_uuid ⇒ Object
42 43 44 |
# File 'lib/rubyists::opr/model/item.rb', line 42 def vault_uuid @vault_uuid ||= raw['vaultUuid'] end |