Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding nested meta objects to the meta hash. moving relationship meta… #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/json-api-vanilla/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/json-api-vanilla/diff_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 3 additions & 0 deletions spec/json-api-vanilla/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
},
"links": {
"self": "http://example.com/people/9"
},
"meta": {
"version": "7"
}
}, {
"type": "comments",
Expand Down