lib/iri.rb in iri-0.7.0 vs lib/iri.rb in iri-0.8.0
- old
+ new
@@ -1,10 +1,10 @@
# frozen_string_literal: true
# (The MIT License)
#
-# Copyright (c) 2019-2023 Yegor Bugayenko
+# Copyright (c) 2019-2024 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -40,16 +40,19 @@
#
# For more information read
# {README}[https://github.com/yegor256/iri/blob/master/README.md] file.
#
# Author:: Yegor Bugayenko (yegor256@gmail.com)
-# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
+# Copyright:: Copyright (c) 2019-2024 Yegor Bugayenko
# License:: MIT
class Iri
# When URI is not valid.
class InvalidURI < StandardError; end
+ # When .add(), .over(), or .del() arguments are not valid.
+ class InvalidArguments < StandardError; end
+
# Makes a new object.
#
# You can even ignore the argument, which will produce an empty URI.
#
# By default, this class will never throw any exceptions, even if your URI
@@ -86,10 +89,11 @@
# only one instance of a query argument, use +del+ first:
#
# Iri.new('https://google.com').del(:q).add(q: 'test')
#
def add(hash)
+ raise InvalidArguments unless hash.is_a?(Hash)
modify_query do |params|
hash.each do |k, v|
params[k.to_s] = [] unless params[k.to_s]
params[k.to_s] << v
end
@@ -113,9 +117,10 @@
# Replace query argument(s).
#
# Iri.new('https://google.com?q=test').over(q: 'hey you!')
#
def over(hash)
+ raise InvalidArguments unless hash.is_a?(Hash)
modify_query do |params|
hash.each do |k, v|
params[k.to_s] = [] unless params[k]
params[k.to_s] = [v]
end