Class: ContentfulLite::EntriesArray
- Defined in:
- lib/contentful_lite/entries_array.rb
Instance Attribute Summary
Attributes inherited from BaseArray
Instance Method Summary collapse
-
#initialize(raw) ⇒ EntriesArray
constructor
private
A new instance of EntriesArray.
Methods inherited from BaseArray
Constructor Details
#initialize(raw) ⇒ EntriesArray
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of EntriesArray.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/contentful_lite/entries_array.rb', line 5 def initialize(raw) super(raw) # Collect arrays of missing (unresolvable) links @errors = raw.fetch('errors', []).collect! { |error| error.fetch('details', {}) }.each_with_object({}) do |error_detail, hash| type = error_detail['linkType'].downcase.to_sym hash[type] ||= [] hash[type] << error_detail['id'] end # Create the array of asset objects @assets = hash_by_id( raw.fetch('includes', {}).fetch('Asset', []) ).transform_values! { |asset| ContentfulLite::Asset.new(asset) } # Now parse the entries, this is the tricky part @entries = {} @raw_entries = hash_by_id( raw.fetch('items', []) + raw.fetch('includes', {}).fetch('Entry', []) ) @items.collect! { |item| build_entry(item['sys']['id']) } end |