Class: TeamSerializer

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

Class Method Summary collapse

Class Method Details

.from_json(json, folders_json: []) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/serializers/team_serializer.rb', line 5

def from_json(json, folders_json: [])
  json = JSON.parse(json, symbolize_names: true)
  data = json[:data] || json
  attributes = data[:attributes]
  folder_ids = data[:relationships][:folders][:data].map { |folder| folder[:id] }
  folders = folders_json.map do |folder|
    FolderSerializer.from_json(folder.to_json) if folder_ids.include?(folder[:id])
  end.compact
  Team.new(name: attributes[:name],
           folders: folders,
           id: data[:id])
end