Skip to content

Commit

Permalink
Provide an exception class and message as arguments to raise
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Dec 6, 2016
1 parent 6253568 commit b195eff
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ Style/Documentation:
Style/ModuleFunction:
Enabled: false

Style/RaiseArgs:
EnforcedStyle: compact

Style/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space

Expand Down
6 changes: 3 additions & 3 deletions lib/multi_xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions lib/multi_xml/parsers/libxml2_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/multi_xml/parsers/ox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/multi_xml/parsers/rexml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b195eff

Please sign in to comment.