diff --git a/parser/jsonapi-parser.gemspec b/parser/jsonapi-parser.gemspec index 577fc8b..a9c7618 100644 --- a/parser/jsonapi-parser.gemspec +++ b/parser/jsonapi-parser.gemspec @@ -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 diff --git a/parser/lib/jsonapi/parser.rb b/parser/lib/jsonapi/parser.rb index b66801b..6493dab 100644 --- a/parser/lib/jsonapi/parser.rb +++ b/parser/lib/jsonapi/parser.rb @@ -1,5 +1,3 @@ -require 'json' - require 'jsonapi/parser/attributes' require 'jsonapi/parser/document' require 'jsonapi/parser/error' @@ -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) end end diff --git a/parser/spec/parser_spec.rb b/parser/spec/parser_spec.rb index 6ea54f5..649b8a4 100644 --- a/parser/spec/parser_spec.rb +++ b/parser/spec/parser_spec.rb @@ -110,4 +110,10 @@ .to raise_error JSONAPI::Parser::InvalidDocument end end + + it 'raises InvalidDocument on nil input' do + expect { + JSONAPI.parse(nil) + }.to raise_error JSONAPI::Parser::InvalidDocument + end end