Class: Folder

Inherits:
Object
  • Object
show all
Defined in:
lib/models/folder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, id: nil, encryptables: []) ⇒ Folder

Returns a new instance of Folder.



6
7
8
9
10
# File 'lib/models/folder.rb', line 6

def initialize(name: nil, id: nil, encryptables: [])
  @name = name
  @id = id
  @encryptables = encryptables
end

Instance Attribute Details

#encryptablesObject (readonly)

Returns the value of attribute encryptables.



4
5
6
# File 'lib/models/folder.rb', line 4

def encryptables
  @encryptables
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/models/folder.rb', line 4

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/models/folder.rb', line 4

def name
  @name
end

Class Method Details

.find(id) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/models/folder.rb', line 13

def find(id)
  json = JSON.parse(CryptopusAdapter.new.get("folders/#{id}"),
                    symbolize_names: true)
  included = json[:included] || []
  name = json[:data][:attributes][:name]
  encryptables = included.map do |record|
    Encryptable.from_json(record.to_json) if %w[encryptable_ose_secrets
                                            encryptable_credentials].include? record[:type]
  end.compact
  Folder.new(id: id, name: name, encryptables: encryptables)
end