Class: SyncResponse

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/schemas.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_dynamic!(d) ⇒ Object



3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
# File 'lib/schemas.rb', line 3407

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    ciphers:     d.fetch("ciphers").map { |x| Cipher.from_dynamic!(x) },
    collections: d.fetch("collections").map { |x| Collection.from_dynamic!(x) },
    domains:     d["domains"] ? DomainResponse.from_dynamic!(d["domains"]) : nil,
    folders:     d.fetch("folders").map { |x| Folder.from_dynamic!(x) },
    profile:     ProfileResponse.from_dynamic!(d.fetch("profile")),
  )
end

.from_json!(json) ⇒ Object



3418
3419
3420
# File 'lib/schemas.rb', line 3418

def self.from_json!(json)
  from_dynamic!(JSON.parse(json))
end

Instance Method Details

#to_dynamicObject



3422
3423
3424
3425
3426
3427
3428
3429
3430
# File 'lib/schemas.rb', line 3422

def to_dynamic
  {
    "ciphers"     => ciphers.map { |x| x.to_dynamic },
    "collections" => collections.map { |x| x.to_dynamic },
    "domains"     => domains&.to_dynamic,
    "folders"     => folders.map { |x| x.to_dynamic },
    "profile"     => profile.to_dynamic,
  }
end

#to_json(options = nil) ⇒ Object



3432
3433
3434
# File 'lib/schemas.rb', line 3432

def to_json(options = nil)
  JSON.generate(to_dynamic, options)
end