Class: AccountSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/serializers/account_serializer.rb

Class Method Summary collapse

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()
  {
    data: {
      type: 'accounts',
      id: .id,
      attributes: {
        accountname: .accountname,
        type: .type,
        cleartext_username: .username,
        cleartext_password: .password,
        ose_secret: .ose_secret
      },
      relationships: {
        folder: {
          data: {
            id: .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()
  OSESecret.new(.accountname, .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()
  { 'id' => .id,
    'accountname' => .accountname,
    'username' => .username,
    'password' => .password,
    'type' => .type }.to_yaml
end