diff --git a/lib/json-api-vanilla/parser.rb b/lib/json-api-vanilla/parser.rb index 0140b85..d5b8b7c 100644 --- a/lib/json-api-vanilla/parser.rb +++ b/lib/json-api-vanilla/parser.rb @@ -52,6 +52,7 @@ def self.build(hash) links = {} # Object links. rel_links = {} # Relationship links. meta = {} # Meta information. + rel_meta = {} # Relationship meta information. # Map from objects to map from keys to values, for use when two keys are # converted to the same ruby method identifier. original_keys = {} @@ -64,6 +65,10 @@ def self.build(hash) links[obj] = o_hash['links'] end + if o_hash['meta'] + meta[obj] = o_hash['meta'] + end + objects[[obj.type, obj.id]] = obj end @@ -100,9 +105,8 @@ def self.build(hash) ref = ref || Object.new set_key(obj, key, ref, original_keys) - rel_links[ref] = value['links'] - meta[ref] = value['meta'] + rel_meta[ref] = value['meta'] end end end diff --git a/spec/json-api-vanilla/diff_spec.rb b/spec/json-api-vanilla/diff_spec.rb index 62e948c..8c225a5 100644 --- a/spec/json-api-vanilla/diff_spec.rb +++ b/spec/json-api-vanilla/diff_spec.rb @@ -44,6 +44,10 @@ expect(doc.meta[doc.data]['from']).to eql("http://jsonapi.org") end + it "should give access to nested meta information" do + expect(doc.meta[doc.data[0].author]['version']).to eql("7") + end + it "should support reference cycles" do json = <<-JSON { diff --git a/spec/json-api-vanilla/example.json b/spec/json-api-vanilla/example.json index 0947c95..4c89495 100644 --- a/spec/json-api-vanilla/example.json +++ b/spec/json-api-vanilla/example.json @@ -46,6 +46,9 @@ }, "links": { "self": "http://example.com/people/9" + }, + "meta": { + "version": "7" } }, { "type": "comments",