Class: EncryptableSerializer
- Inherits:
-
Object
- Object
- EncryptableSerializer
- Defined in:
- lib/serializers/encryptable_serializer.rb
Class Method Summary collapse
- .from_json(json) ⇒ Object
-
.to_json(encryptable) ⇒ Object
rubocop:disable Metrics/MethodLength.
- .to_osesecret(account) ⇒ Object
-
.to_yaml(encryptable) ⇒ Object
rubocop:enable Metrics/MethodLength.
Class Method Details
.from_json(json) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/serializers/encryptable_serializer.rb', line 41 def from_json(json) json = JSON.parse(json, symbolize_names: true) data = json[:data] || json attributes = data[:attributes] Encryptable.new(name: attributes[:name], username: attributes[:cleartext_username], password: attributes[:cleartext_password], ose_secret: attributes[:ose_secret], type: attributes[:type], id: data[:id]) end |
.to_json(encryptable) ⇒ Object
rubocop:disable Metrics/MethodLength
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/serializers/encryptable_serializer.rb', line 8 def to_json(encryptable) { data: { type: 'encryptables', id: encryptable.id, attributes: { name: encryptable.name, type: encryptable.type, cleartext_username: encryptable.username, cleartext_password: encryptable.password, cleartext_ose_secret: encryptable.ose_secret }, relationships: { folder: { data: { id: encryptable.folder, type: 'folders' } } } } }.compact.to_json end |
.to_osesecret(account) ⇒ Object
53 54 55 |
# File 'lib/serializers/encryptable_serializer.rb', line 53 def to_osesecret(account) OSESecret.from_yaml(account.ose_secret) end |
.to_yaml(encryptable) ⇒ Object
rubocop:enable Metrics/MethodLength
33 34 35 36 37 38 39 |
# File 'lib/serializers/encryptable_serializer.rb', line 33 def to_yaml(encryptable) { 'id' => encryptable.id, 'name' => encryptable.name, 'username' => encryptable.username, 'password' => encryptable.password, 'type' => encryptable.type }.to_yaml end |