diff --git a/lib/literal/enum.rb b/lib/literal/enum.rb index ad9bc36..f6d25d1 100644 --- a/lib/literal/enum.rb +++ b/lib/literal/enum.rb @@ -40,7 +40,7 @@ def index(name, type, unique: true, &block) def where(**kwargs) unless kwargs.length == 1 - raise ArgumentError, "You can only specify one index when using `where`." + raise ArgumentError.new("You can only specify one index when using `where`.") end key, value = kwargs.first @@ -54,13 +54,13 @@ def where(**kwargs) def find_by(**kwargs) unless kwargs.length == 1 - raise ArgumentError, "You can only specify one index when using `where`." + raise ArgumentError.new("You can only specify one index when using `where`.") end key, value = kwargs.first unless @indexes.fetch(key)[1] - raise ArgumentError, "You can only use `find_by` on unique indexes." + raise ArgumentError.new("You can only use `find_by` on unique indexes.") end unless (type = @indexes.fetch(key)[0]) === value @@ -89,7 +89,7 @@ def const_added(name) def new(*, **, &block) raise ArgumentError if frozen? - new_object = super(*, **, &nil) + new_object = super(*, **, &nil) if block new_object.instance_exec(&block) @@ -101,7 +101,6 @@ def new(*, **, &block) def __after_defined__ raise ArgumentError if frozen? - @indexes.each do |name, (type, unique, block)| index = @members.group_by(&block).freeze @@ -111,14 +110,13 @@ def __after_defined__ end if unique && values.size > 1 - raise ArgumentError, "The index #{name} is not unique." + raise ArgumentError.new("The index #{name} is not unique.") end end @index[name] = index end - @values.freeze @members.freeze freeze diff --git a/test/enum.test.rb b/test/enum.test.rb index bf91d03..cdfe04a 100644 --- a/test/enum.test.rb +++ b/test/enum.test.rb @@ -30,7 +30,7 @@ def toggle = On expect(Color::Red.name) =~ /Color::Red\z/ expect(Color.where(hex: "#FF0000")) == [Color::Red] expect(Color.find_by(hex: "#FF0000")) == Color::Red - expect { Color.find_by(lower_hex: "#ff0000")}.to_raise(ArgumentError) + expect { Color.find_by(lower_hex: "#ff0000") }.to_raise(ArgumentError) expect(Color.where(lower_hex: "#ff0000")) == [Color::Red] expect(Color::Red.value) == 1 expect(Color::Red.hex) == "#FF0000"