class JsonAPIObjectMapper::Deserialize::Collection

Attributes

collection_data[R]

Public Class Methods

new(parser, klass:) click to toggle source
# File lib/jsonapi-object-mapper/deserialize/collection.rb, line 16
def initialize(parser, klass:)
  raise InvalidResource unless klass.is_a?(Class)
  raise InvalidParser   unless parser.is_a?(JsonAPIObjectMapper::Parser::Document)
  @errors            = parser.errors
  @links             = parser.links
  @collection_data   =
    if document_invalid?
      []
    else
      Array(parser.document_data).map do |doc|
        klass.new(parser, document: doc)
      end
    end.freeze

  freeze
end

Public Instance Methods

each() { |data| ... } click to toggle source
# File lib/jsonapi-object-mapper/deserialize/collection.rb, line 33
def each
  @collection_data.each do |data|
    yield data
  end
end
inspect() click to toggle source
# File lib/jsonapi-object-mapper/deserialize/collection.rb, line 39
def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)}, "\
  "@errors=#{@errors.inspect}, "\
  "@links=#{@links.inspect}, "\
  "@data=#{@collection_data.map(&:inspect)}>"\
end
Also aliased as: to_s
to_h()
Alias for: to_hash
to_hash() click to toggle source
# File lib/jsonapi-object-mapper/deserialize/collection.rb, line 47
def to_hash
  {}.tap do |hash|
    hash[:data]   = @collection_data.map(&:to_hash)
    hash[:links]  = @links.to_h unless @links.nil?
    hash[:errors] = @errors unless valid?
  end
end
Also aliased as: to_h
to_s()
Alias for: inspect