Skip to content

Commit

Permalink
Merge branch 'hotfix/0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
thornomad committed Apr 29, 2020
2 parents 97d1b60 + 1f8e94c commit c7c63b6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PATH
remote: .
specs:
enumbler (0.3.0)
activerecord (>= 6.0)
activesupport (>= 6.0)
enumbler (0.3.1)
activerecord (~> 6.0.2)
activesupport (~> 6.0.2)

GEM
remote: https://rubygems.org/
Expand Down
4 changes: 2 additions & 2 deletions enumbler.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'activerecord', '>= 6.0'
spec.add_dependency 'activesupport', '>= 6.0'
spec.add_dependency 'activerecord', '~> 6.0.2'
spec.add_dependency 'activesupport', '~> 6.0.2'

spec.add_development_dependency 'database_cleaner-active_record', '~> 1.8.0'
spec.add_development_dependency 'fuubar', '~> 2.5'
Expand Down
21 changes: 18 additions & 3 deletions lib/enumbler/enabler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,24 @@ def enumble(enum, id, label: nil, **options)
@enumbles << enumble
end

# Return the record id(s) based on different argument types. Can accept an
# Integer, a Symbol, or an instance of Enumbled model. This lookup is a
# databse-free lookup.
# Return the record id for a given argument. Can accept an Integer, a
# Symbol, or an instance of Enumbled model. This lookup is a database-free
# lookup.
#
# Color.id_from_enumbler(1) # => 1
# Color.id_from_enumbler(:black) # => 1
# Color.id_from_enumbler(Color.black) # => 1
#
# @raise [Error] when there is no enumble to be found
# @param arg [Integer, Symbol, Class]
# @return [Integer]
def id_from_enumbler(arg)
ids_from_enumbler(arg).first
end

# Return the record id(s) based on different argument types. Can accept
# an Integer, a Symbol, or an instance of Enumbled model. This lookup is
# a database-free lookup.
#
# Color.ids_from_enumbler(1, 2) # => [1, 2]
# Color.ids_from_enumbler(:black, :white) # => [1, 2]
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.3.0'
VERSION = '0.3.1'
end
2 changes: 2 additions & 0 deletions spec/enumbler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,14 @@ class House < ApplicationRecord

describe '.ids_from_enumbler', :seed do
it 'returns a numeric id' do
expect(Color.id_from_enumbler(1)).to eq 1
expect(Color.ids_from_enumbler(1)).to contain_exactly(1)
end
it 'raises an error when the id is not defined' do
expect { Color.ids_from_enumbler(100, 1) }.to raise_error(Enumbler::Error, /Unable to find/)
end
it 'returns an id from a symbol' do
expect(Color.id_from_enumbler(:black)).to eq 1
expect(Color.ids_from_enumbler(:black)).to contain_exactly(1)
expect(Color.ids_from_enumbler(:black, :white)).to contain_exactly(1, 2)
end
Expand Down

0 comments on commit c7c63b6

Please sign in to comment.