Skip to content

Commit

Permalink
Rubocop fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Jun 25, 2024
1 parent ca7f1c0 commit 959340b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions lib/literal/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/enum.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 959340b

Please sign in to comment.