Class: AccountSerializer
- Inherits:
-
Object
- Object
- AccountSerializer
- Defined in:
- lib/serializers/account_serializer.rb
Class Method Summary collapse
- .from_json(json) ⇒ Object
-
.to_json(account) ⇒ Object
rubocop:disable Metrics/MethodLength.
- .to_osesecret(account) ⇒ Object
-
.to_yaml(account) ⇒ 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/account_serializer.rb', line 41 def from_json(json) json = JSON.parse(json, symbolize_names: true) data = json[:data] || json attributes = data[:attributes] Account.new(accountname: attributes[:accountname], username: attributes[:cleartext_username], password: attributes[:cleartext_password], ose_secret: attributes[:ose_secret], type: attributes[:type], id: data[:id]) end |
.to_json(account) ⇒ 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/account_serializer.rb', line 8 def to_json(account) { data: { type: 'accounts', id: account.id, attributes: { accountname: account.accountname, type: account.type, cleartext_username: account.username, cleartext_password: account.password, ose_secret: account.ose_secret }, relationships: { folder: { data: { id: account.folder, type: 'folders' } } } } }.compact.to_json end |
.to_osesecret(account) ⇒ Object
53 54 55 |
# File 'lib/serializers/account_serializer.rb', line 53 def to_osesecret(account) OSESecret.new(account.accountname, account.ose_secret) end |
.to_yaml(account) ⇒ Object
rubocop:enable Metrics/MethodLength
33 34 35 36 37 38 39 |
# File 'lib/serializers/account_serializer.rb', line 33 def to_yaml(account) { 'id' => account.id, 'accountname' => account.accountname, 'username' => account.username, 'password' => account.password, 'type' => account.type }.to_yaml end |