Skip to content
Merged
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
2 changes: 0 additions & 2 deletions parser/jsonapi-parser.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ Gem::Specification.new do |spec|

spec.files = Dir['LICENSE', 'README.md', 'lib/**/*']
spec.require_path = 'lib'

spec.add_dependency 'json', '~>1.8'
end
9 changes: 3 additions & 6 deletions parser/lib/jsonapi/parser.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'json'

require 'jsonapi/parser/attributes'
require 'jsonapi/parser/document'
require 'jsonapi/parser/error'
Expand All @@ -17,14 +15,13 @@ module JSONAPI

# Parse a JSON API document.
#
# @param document [Hash, String] the JSON API document.
# @param document [Hash] the JSON API document.
# @param options [Hash] options
# @option options [Boolean] :id_optional (false) Whether the resource
# objects in the primary data must have an id.
# @return [JSONAPI::Parser::Document]
def parse(document, options = {})
hash = document.is_a?(Hash) ? document : JSON.parse(document)

Parser::Document.new(hash, options)
raise Parser::InvalidDocument, 'document must be a hash' unless document.is_a?(Hash)
Parser::Document.new(document, options)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, then you can also remove the dependency to json in both this file and the gemspec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

end
end
6 changes: 6 additions & 0 deletions parser/spec/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,10 @@
.to raise_error JSONAPI::Parser::InvalidDocument
end
end

it 'raises InvalidDocument on nil input' do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

expect {
JSONAPI.parse(nil)
}.to raise_error JSONAPI::Parser::InvalidDocument
end
end