Skip to content

Commit

Permalink
Merge branch 'hotfix/0.6.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
thornomad committed Aug 4, 2020
2 parents 1b81de3 + 081933f commit 4b20fe7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
enumbler (0.6.5)
enumbler (0.6.6)
activerecord (>= 5.2.3, < 6.1)
activesupport (>= 5.2.3, < 6.1)

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ Color.find_enumbles(:black, 'does-not-exist') # => [Enumbler::Enumble<:black>, n

Color.find_enumble(:black) # => Enumbler::Enumble<:black>

# Is pretty flexible with findidng things from strings
Color.find_enumble('Dark_Brown') # => Enumbler::Enumble<:dark-brown>

# raises errors if none found
Color.find_enumbles!!(:black, 'does-no-exist') # => raises Enumbler::Error
Color.find_enumble!(:does_not_exist) # => raises Enumbler::Error
Expand Down
6 changes: 5 additions & 1 deletion lib/enumbler/enabler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ def find_enumbles(*args, case_sensitive: false, raise_error: false)
@enumbled_model.enumbles.find { |e| e.enum == arg }
elsif arg.is_a?(String)
@enumbled_model.enumbles.find do |e|
case_sensitive ? e.label == arg : arg.casecmp?(e.label)
if case_sensitive
[e.label, e.enum.to_s].include?(arg)
else
arg.casecmp?(e.label) || arg.casecmp?(e.enum.to_s)
end
end
elsif arg.instance_of?(@enumbled_model)
arg.enumble
Expand Down
2 changes: 1 addition & 1 deletion lib/enumbler/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Enumbler
VERSION = '0.6.5'
VERSION = '0.6.6'
end
2 changes: 2 additions & 0 deletions spec/enumbler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class ModelWithoutTable < ApplicationRecord
expect(Color.id_from_enumbler('dark-brown')).to eq 3
expect(Color.ids_from_enumbler('dark-brown')).to contain_exactly(3)
expect(Color.ids_from_enumbler('dark-Brown', 'black')).to contain_exactly(1, 3)
expect(Color.ids_from_enumbler('dark_brown', 'black')).to contain_exactly(1, 3)
expect(Color.id_from_enumbler('BlaCk')).to eq 1
end
end
Expand All @@ -247,6 +248,7 @@ class ModelWithoutTable < ApplicationRecord
it 'returns an id from a string' do
expect(Color.ids_from_enumbler('black', case_sensitive: true)).to contain_exactly(1)
expect(Color.ids_from_enumbler('black', :white, case_sensitive: true)).to contain_exactly(1, 2)
expect(Color.ids_from_enumbler('dark_brown', :white, case_sensitive: true)).to contain_exactly(2, 3)
expect { Color.ids_from_enumbler!('Black', case_sensitive: true) }.to raise_error(Enumbler::Error, /Black/)
expect(Color.id_from_enumbler('black', case_sensitive: true)).to eq(1)
expect(Color.id_from_enumbler('black', case_sensitive: true)).to eq(1)
Expand Down

0 comments on commit 4b20fe7

Please sign in to comment.