Class: Cipher

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



2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
# File 'lib/schemas.rb', line 2886

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    attachments:           d["attachments"]&.map { |x| Attachment.from_dynamic!(x) },
    card:                  d["card"] ? Card.from_dynamic!(d["card"]) : nil,
    collection_ids:        d.fetch("collectionIds"),
    creation_date:         d.fetch("creationDate"),
    deleted_date:          d["deletedDate"],
    edit:                  d.fetch("edit"),
    favorite:              d.fetch("favorite"),
    fields:                d["fields"]&.map { |x| Field.from_dynamic!(x) },
    folder_id:             d["folderId"],
    id:                    d["id"],
    identity:              d["identity"] ? Identity.from_dynamic!(d["identity"]) : nil,
    key:                   d["key"],
    local_data:            d["localData"] ? LocalData.from_dynamic!(d["localData"]) : nil,
    login:                 d["login"] ? Login.from_dynamic!(d["login"]) : nil,
    cipher_name:           d.fetch("name"),
    notes:                 d["notes"],
    organization_id:       d["organizationId"],
    organization_use_totp: d.fetch("organizationUseTotp"),
    password_history:      d["passwordHistory"]&.map { |x| PasswordHistory.from_dynamic!(x) },
    reprompt:              d.fetch("reprompt"),
    revision_date:         d.fetch("revisionDate"),
    secure_note:           d["secureNote"] ? SecureNote.from_dynamic!(d["secureNote"]) : nil,
    cipher_type:           d.fetch("type"),
    view_password:         d.fetch("viewPassword"),
  )
end

.from_json!(json) ⇒ Object



2916
2917
2918
# File 'lib/schemas.rb', line 2916

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

Instance Method Details

#to_dynamicObject



2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
# File 'lib/schemas.rb', line 2920

def to_dynamic
  {
    "attachments"         => attachments&.map { |x| x.to_dynamic },
    "card"                => card&.to_dynamic,
    "collectionIds"       => collection_ids,
    "creationDate"        => creation_date,
    "deletedDate"         => deleted_date,
    "edit"                => edit,
    "favorite"            => favorite,
    "fields"              => fields&.map { |x| x.to_dynamic },
    "folderId"            => folder_id,
    "id"                  => id,
    "identity"            => identity&.to_dynamic,
    "key"                 => key,
    "localData"           => local_data&.to_dynamic,
    "login"               => &.to_dynamic,
    "name"                => cipher_name,
    "notes"               => notes,
    "organizationId"      => organization_id,
    "organizationUseTotp" => organization_use_totp,
    "passwordHistory"     => password_history&.map { |x| x.to_dynamic },
    "reprompt"            => reprompt,
    "revisionDate"        => revision_date,
    "secureNote"          => secure_note&.to_dynamic,
    "type"                => cipher_type,
    "viewPassword"        => view_password,
  }
end

#to_json(options = nil) ⇒ Object



2949
2950
2951
# File 'lib/schemas.rb', line 2949

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