Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Metrics/BlockLength:
RSpec/SpecFilePathFormat:
Enabled: false

Style/LineLength:
Layout/LineLength:
Enabled: false

Style/HashEachMethods:
Expand All @@ -38,6 +38,9 @@ RSpec/NestedGroups:
RSpec/ExampleLength:
Enabled: false

RSpec/DescribedClass:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

Expand Down
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
### 1.1.0 (Next)
### 1.2.0 (Next)

* Your contribution here.

### 1.1.0 (2026/6/20)

* [#56](https://github.com/dblock/ruby-enum/pull/56): Fix `DuplicateKeyError` when the enum class is reloaded - [@flvrone](https://github.com/flvrone).
* [#54](https://github.com/dblock/ruby-enum/pull/54): Add support for Ruby 4.0 - [@dblock](https://github.com/dblock).
* [#53](https://github.com/dblock/ruby-enum/pull/53): Replace code climate with coveralls - [@dblock](https://github.com/dblock).
* Your contribution here.

### 1.0.0 (2023/01/10)

Expand Down
19 changes: 14 additions & 5 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ bundle install
rake
```

Check that the last build succeeded in [Travis CI](https://travis-ci.org/dblock/ruby-enum) for all supported platforms.
Check that the last build succeeded in [GitHub Actions](https://github.com/dblock/ruby-enum/actions) for all supported platforms.

Add a date to this release in [CHANGELOG.md](CHANGELOG.md).

Expand All @@ -28,15 +28,24 @@ git add README.md CHANGELOG.md lib/ruby-enum/version.rb
git commit -m "Preparing for release, 0.2.2."
```

Release.
Release. If you have MFA enabled on RubyGems (you should), `rake release` will build the gem, tag it, and push commits/tags to GitHub, but fail at the RubyGems push. Push the gem manually with your OTP.

```
$ rake release

ruby-enum 0.2.2 built to pkg/ruby-enum-0.2.2.gem.
Tagged v0.2.2.
ruby-enum 1.1.0 built to pkg/ruby-enum-1.1.0.gem.
Tagged v1.1.0.
Pushed git commits and tags.
Pushed ruby-enum 0.2.2 to rubygems.org.
...
You have enabled multi-factor authentication. Please enter OTP code.
```

Then push to RubyGems manually:

```
$ gem push pkg/ruby-enum-1.1.0.gem --otp <OTP>
Pushing gem to https://rubygems.org...
Successfully registered gem: ruby-enum (1.1.0)
```

### Prepare for the Next Version
Expand Down
3 changes: 3 additions & 0 deletions lib/ruby-enum/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def self.included(base)
base.extend ClassMethods

base.private_class_method(:new)

base.instance_variable_set(:@_enum_hash, {})
base.instance_variable_set(:@_enums_by_value, {})
end

module ClassMethods
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-enum/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Ruby
module Enum
VERSION = '1.1.0'
VERSION = '1.2.0'
end
end
54 changes: 54 additions & 0 deletions spec/ruby-enum/enum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ class FirstSubclass < Colors
class SecondSubclass < FirstSubclass
define :PINK, 'pink'
end

class OtherSecondSubclass < FirstSubclass
include Ruby::Enum

define :MAGENTA, 'magenta'
end

it 'returns an enum value' do
expect(Colors::RED).to eq 'red'
expect(Colors::GREEN).to eq 'green'
Expand Down Expand Up @@ -169,6 +176,12 @@ class SecondSubclass < FirstSubclass
expect(SecondSubclass.values).to eq(%w[red green orange pink])
end
end

context 'when a subclass of a subclass is defined with redundant module inclusion' do
it 'returns all values' do
expect(OtherSecondSubclass.values).to eq(%w[red green orange magenta])
end
end
end

describe '#to_h' do
Expand Down Expand Up @@ -229,6 +242,47 @@ class SecondSubclass < FirstSubclass
end
end

describe 'Reloading enum definition' do
it 'can be lazy reloaded' do
class_body = proc do
include Ruby::Enum

define :BUZZ_CUT, 'buzz_cut'
end

hair_styles = Class.new(&class_body)

expect { hair_styles.class_eval(&class_body) }.not_to raise_error
end

context 'when a subclass is defined' do
it 'NEEDS to include Ruby::Enum explicitly to be lazy reloaded' do
hair_styles = Class.new do
include Ruby::Enum

define :BUZZ_CUT, 'buzz_cut'
end

broken_subclass_body = proc do
define :PONYTAIL, 'ponytail'
end
broken_subclass = Class.new(hair_styles, &broken_subclass_body)
expect { broken_subclass.class_eval(&broken_subclass_body) }
.to raise_error Ruby::Enum::Errors::DuplicateKeyError, /PONYTAIL/

subclass_body = proc do
include Ruby::Enum

define :PONYTAIL, 'ponytail'
end
more_hair_styles = Class.new(hair_styles, &subclass_body)

expect { more_hair_styles.class_eval(&subclass_body) }.not_to raise_error
expect(more_hair_styles.values).to eq(%w[buzz_cut ponytail])
end
end
end

describe 'Given a class that has not defined any enums' do
class EmptyEnums
include Ruby::Enum
Expand Down
Loading