Class: TeamApi::CollectionCanonicalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/team_api/collection_canonicalizer.rb

Class Method Summary collapse

Class Method Details

.parse_collection_spec(collection_spec) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/team_api/collection_canonicalizer.rb', line 47

def self.parse_collection_spec(collection_spec)
  if collection_spec.instance_of? Hash
    [collection_spec['field'],
     Config.endpoint_info_by_collection[collection_spec['collection']]]
  else
    [collection_spec, Config.endpoint_info_by_collection[collection_spec]]
  end
end

.sort_collections(site_data) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/team_api/collection_canonicalizer.rb', line 8

def self.sort_collections(site_data)
  Config.endpoint_config.each do |endpoint_info|
    collection = endpoint_info['collection']
    next unless site_data.member? collection
    sorted = sort_collection_values(endpoint_info,
      site_data[collection].values)
    sort_item_xrefs endpoint_info, sorted
    item_id_field = endpoint_info['item_id']
    site_data[collection] = sorted.map { |i| [i[item_id_field], i] }.to_h
  end
end