From b195eff9f8f12df850d4f6554910dda6c6a6a4fa Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Tue, 6 Dec 2016 00:02:21 -0800 Subject: [PATCH] Provide an exception class and message as arguments to raise --- .rubocop.yml | 3 --- lib/multi_xml.rb | 6 +++--- lib/multi_xml/parsers/libxml2_parser.rb | 8 ++++---- lib/multi_xml/parsers/ox.rb | 2 +- lib/multi_xml/parsers/rexml.rb | 2 +- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 401f0a1..8f0d41a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -36,9 +36,6 @@ Style/Documentation: Style/ModuleFunction: Enabled: false -Style/RaiseArgs: - EnforcedStyle: compact - Style/SpaceInsideHashLiteralBraces: EnforcedStyle: no_space diff --git a/lib/multi_xml.rb b/lib/multi_xml.rb index 393810c..c8767d8 100644 --- a/lib/multi_xml.rb +++ b/lib/multi_xml.rb @@ -98,7 +98,7 @@ def default_parser next end end - raise(NoParserError.new("No XML parser detected. If you're using Rubinius and Bundler, try adding an XML parser to your Gemfile (e.g. libxml-ruby, nokogiri, or rubysl-rexml). For more information, see https://github.com/sferik/multi_xml/issues/42.")) + raise(NoParserError, "No XML parser detected. If you're using Rubinius and Bundler, try adding an XML parser to your Gemfile (e.g. libxml-ruby, nokogiri, or rubysl-rexml). For more information, see https://github.com/sferik/multi_xml/issues/42.") end # Set the XML parser utilizing a symbol, string, or class. @@ -148,7 +148,7 @@ def parse(xml, options = {}) # rubocop:disable AbcSize, CyclomaticComplexity, Me rescue DisallowedTypeError raise rescue parser.parse_error => error - raise(ParseError, error.message, error.backtrace) # rubocop:disable RaiseArgs + raise(ParseError, error.message, error.backtrace) end hash = symbolize_keys(hash) if options[:symbolize_keys] hash @@ -221,7 +221,7 @@ def typecast_xml_value(value, disallowed_types = nil) # rubocop:disable AbcSize, case value when Hash if value.include?('type') && !value['type'].is_a?(Hash) && disallowed_types.include?(value['type']) - raise(DisallowedTypeError.new(value['type'])) + raise(DisallowedTypeError, value['type']) end if value['type'] == 'array' diff --git a/lib/multi_xml/parsers/libxml2_parser.rb b/lib/multi_xml/parsers/libxml2_parser.rb index b058991..13943e8 100644 --- a/lib/multi_xml/parsers/libxml2_parser.rb +++ b/lib/multi_xml/parsers/libxml2_parser.rb @@ -51,21 +51,21 @@ def node_to_hash(node, hash = {}) # rubocop:disable AbcSize, CyclomaticComplexit # xml:: # XML Document IO to parse def parse(_) - raise(NotImplementedError.new("inheritor should define #{__method__}")) + raise(NotImplementedError, "inheritor should define #{__method__}") end private def each_child(*) - raise(NotImplementedError.new("inheritor should define #{__method__}")) + raise(NotImplementedError, "inheritor should define #{__method__}") end def each_attr(*) - raise(NotImplementedError.new("inheritor should define #{__method__}")) + raise(NotImplementedError, "inheritor should define #{__method__}") end def node_name(*) - raise(NotImplementedError.new("inheritor should define #{__method__}")) + raise(NotImplementedError, "inheritor should define #{__method__}") end end end diff --git a/lib/multi_xml/parsers/ox.rb b/lib/multi_xml/parsers/ox.rb index 74a6640..e52a560 100644 --- a/lib/multi_xml/parsers/ox.rb +++ b/lib/multi_xml/parsers/ox.rb @@ -68,7 +68,7 @@ def end_element(_) end def error(message, line, column) - raise(Exception.new("#{message} at #{line}:#{column}")) + raise(Exception, "#{message} at #{line}:#{column}") end def append(key, value) diff --git a/lib/multi_xml/parsers/rexml.rb b/lib/multi_xml/parsers/rexml.rb index c2f77c1..9633713 100644 --- a/lib/multi_xml/parsers/rexml.rb +++ b/lib/multi_xml/parsers/rexml.rb @@ -15,7 +15,7 @@ def parse_error # XML Document IO to parse def parse(xml) doc = REXML::Document.new(xml) - raise(REXML::ParseException.new("The document #{doc.to_s.inspect} does not have a valid root")) unless doc.root + raise(REXML::ParseException, "The document #{doc.to_s.inspect} does not have a valid root") unless doc.root merge_element!({}, doc.root) end