enumerate_it 3.0.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +51 -0
- data/.rubocop.yml +25 -5
- data/Appraisals +2 -2
- data/Gemfile.lock +57 -49
- data/LICENSE +1 -1
- data/README.md +7 -7
- data/Rakefile +4 -11
- data/enumerate_it.gemspec +5 -3
- data/gemfiles/rails_5.1.gemfile +1 -1
- data/gemfiles/rails_5.2.gemfile +3 -3
- data/gemfiles/rails_6.0.gemfile +3 -3
- data/gemfiles/{rails_4.2.gemfile → rails_6.1.gemfile} +3 -3
- data/lib/enumerate_it/base.rb +12 -10
- data/lib/enumerate_it/version.rb +1 -1
- data/spec/enumerate_it/base_spec.rb +17 -1
- data/spec/enumerate_it_spec.rb +12 -2
- data/spec/spec_helper.rb +1 -1
- metadata +26 -12
- data/.travis.yml +0 -31
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 30519e86bb2c6fda44e28d8abb00dba9148ccea033a2c99a363fbf6f2fd42a09
|
|
4
|
+
data.tar.gz: 8f5bd97543dc7f14551829327a324d0830d62de53c46e4d08256d25a200694e7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 34a5e8b29263a13902bea44f4e7fab5c852c74acc4a2670fc35120be6955682e067e893117c9b4eb1cd3c15b99fe89583c8a5ba78b39b83af515e9c998908d5d
|
|
7
|
+
data.tar.gz: 88db7990bde7a0c25ef2ba773038f17741a92da080409f900b1eed5a68c7fe821ed5ef92b55547c59bb24a3cdcdb973a9601518a9c57bb852bba00ec00cd49ef
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
test:
|
|
7
|
+
strategy:
|
|
8
|
+
fail-fast: false
|
|
9
|
+
|
|
10
|
+
matrix:
|
|
11
|
+
ruby:
|
|
12
|
+
- 2.5
|
|
13
|
+
- 2.6
|
|
14
|
+
- 2.7
|
|
15
|
+
- 3.0
|
|
16
|
+
gemfile:
|
|
17
|
+
- gemfiles/rails_5.0.gemfile
|
|
18
|
+
- gemfiles/rails_5.1.gemfile
|
|
19
|
+
- gemfiles/rails_5.2.gemfile
|
|
20
|
+
- gemfiles/rails_6.0.gemfile
|
|
21
|
+
- gemfiles/rails_6.1.gemfile
|
|
22
|
+
exclude:
|
|
23
|
+
# Rails < 6 does not support Ruby 3+:
|
|
24
|
+
# https://github.com/rails/rails/issues/40938#issuecomment-751357907
|
|
25
|
+
- ruby: 3.0
|
|
26
|
+
gemfile: gemfiles/rails_5.0.gemfile
|
|
27
|
+
- ruby: 3.0
|
|
28
|
+
gemfile: gemfiles/rails_5.1.gemfile
|
|
29
|
+
- ruby: 3.0
|
|
30
|
+
gemfile: gemfiles/rails_5.2.gemfile
|
|
31
|
+
|
|
32
|
+
env:
|
|
33
|
+
BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
|
|
34
|
+
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
|
|
37
|
+
steps:
|
|
38
|
+
- name: Checkout
|
|
39
|
+
uses: actions/checkout@v2
|
|
40
|
+
- name: Set up Ruby
|
|
41
|
+
uses: ruby/setup-ruby@v1
|
|
42
|
+
with:
|
|
43
|
+
ruby-version: ${{ matrix.ruby }}
|
|
44
|
+
bundler-cache: true
|
|
45
|
+
|
|
46
|
+
- name: Rubocop
|
|
47
|
+
if: ${{ matrix.ruby == '3.0' }}
|
|
48
|
+
run: "bundle exec rubocop"
|
|
49
|
+
|
|
50
|
+
- name: Tests
|
|
51
|
+
run: bundle exec rake spec
|
data/.rubocop.yml
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
require:
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-rspec
|
|
3
|
+
- rubocop-rake
|
|
2
4
|
|
|
3
5
|
inherit_mode:
|
|
4
6
|
merge:
|
|
5
7
|
- Exclude
|
|
6
8
|
|
|
7
9
|
AllCops:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
NewCops: enable
|
|
11
|
+
TargetRubyVersion: 2.5
|
|
10
12
|
|
|
11
13
|
Exclude:
|
|
12
14
|
- 'lib/generators/enumerate_it/enum/templates/**/*'
|
|
@@ -18,14 +20,20 @@ Gemspec/RequiredRubyVersion:
|
|
|
18
20
|
Layout/EndAlignment:
|
|
19
21
|
Enabled: false
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
Layout/LineLength:
|
|
22
24
|
Max: 100
|
|
23
25
|
|
|
26
|
+
Lint/RaiseException:
|
|
27
|
+
Enabled: true
|
|
28
|
+
|
|
29
|
+
Lint/StructNewOverride:
|
|
30
|
+
Enabled: true
|
|
31
|
+
|
|
24
32
|
Metrics/BlockLength:
|
|
25
33
|
Exclude:
|
|
26
34
|
- 'spec/**/*'
|
|
27
35
|
|
|
28
|
-
Layout/
|
|
36
|
+
Layout/HashAlignment:
|
|
29
37
|
EnforcedColonStyle: table
|
|
30
38
|
EnforcedLastArgumentHashStyle: ignore_implicit
|
|
31
39
|
|
|
@@ -47,10 +55,22 @@ Style/Documentation:
|
|
|
47
55
|
Style/GuardClause:
|
|
48
56
|
MinBodyLength: 3
|
|
49
57
|
|
|
58
|
+
Style/HashEachMethods:
|
|
59
|
+
Enabled: true
|
|
60
|
+
|
|
61
|
+
Style/HashTransformKeys:
|
|
62
|
+
Enabled: true
|
|
63
|
+
|
|
64
|
+
Style/HashTransformValues:
|
|
65
|
+
Enabled: true
|
|
66
|
+
|
|
50
67
|
Naming/PredicateName:
|
|
51
68
|
Exclude:
|
|
52
69
|
- 'lib/enumerate_it/class_methods.rb'
|
|
53
70
|
|
|
71
|
+
Naming/VariableNumber:
|
|
72
|
+
EnforcedStyle: snake_case
|
|
73
|
+
|
|
54
74
|
RSpec/MultipleExpectations:
|
|
55
75
|
Enabled: false
|
|
56
76
|
|
data/Appraisals
CHANGED
|
@@ -4,7 +4,7 @@ require 'json'
|
|
|
4
4
|
rails_versions = JSON.parse(Net::HTTP.get(URI('https://rubygems.org/api/v1/versions/rails.json')))
|
|
5
5
|
.group_by { |version| version['number'] }.keys.reject { |key| key =~ /rc|racecar|beta|pre/ }
|
|
6
6
|
|
|
7
|
-
%w[
|
|
7
|
+
%w[5.0 5.1 5.2 6.0 6.1].each do |version|
|
|
8
8
|
appraise "rails_#{version}" do
|
|
9
9
|
current_version = rails_versions
|
|
10
10
|
.select { |key| key.match(/\A#{version}/) }
|
|
@@ -13,6 +13,6 @@ rails_versions = JSON.parse(Net::HTTP.get(URI('https://rubygems.org/api/v1/versi
|
|
|
13
13
|
gem 'activesupport', "~> #{current_version}"
|
|
14
14
|
gem 'activerecord', "~> #{current_version}"
|
|
15
15
|
|
|
16
|
-
gem 'sqlite3', Gem::Version.new(version) > Gem::Version.new(5.0) ? '~> 1.4.
|
|
16
|
+
gem 'sqlite3', Gem::Version.new(version) > Gem::Version.new(5.0) ? '~> 1.4.2' : '< 1.4'
|
|
17
17
|
end
|
|
18
18
|
end
|
data/Gemfile.lock
CHANGED
|
@@ -1,69 +1,76 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
enumerate_it (3.
|
|
5
|
-
activesupport (>=
|
|
4
|
+
enumerate_it (3.2.1)
|
|
5
|
+
activesupport (>= 5.0.7.2)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
activesupport (6.
|
|
10
|
+
activesupport (6.1.4)
|
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
12
|
-
i18n (>=
|
|
13
|
-
minitest (
|
|
14
|
-
tzinfo (~>
|
|
15
|
-
zeitwerk (~> 2.
|
|
16
|
-
appraisal (2.
|
|
12
|
+
i18n (>= 1.6, < 2)
|
|
13
|
+
minitest (>= 5.1)
|
|
14
|
+
tzinfo (~> 2.0)
|
|
15
|
+
zeitwerk (~> 2.3)
|
|
16
|
+
appraisal (2.4.1)
|
|
17
17
|
bundler
|
|
18
18
|
rake
|
|
19
19
|
thor (>= 0.14.0)
|
|
20
|
-
ast (2.4.
|
|
21
|
-
coderay (1.1.
|
|
22
|
-
concurrent-ruby (1.1.
|
|
23
|
-
diff-lcs (1.
|
|
24
|
-
i18n (1.
|
|
20
|
+
ast (2.4.2)
|
|
21
|
+
coderay (1.1.3)
|
|
22
|
+
concurrent-ruby (1.1.9)
|
|
23
|
+
diff-lcs (1.4.4)
|
|
24
|
+
i18n (1.8.10)
|
|
25
25
|
concurrent-ruby (~> 1.0)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
method_source (~> 0.9.0)
|
|
26
|
+
method_source (1.0.0)
|
|
27
|
+
minitest (5.14.4)
|
|
28
|
+
parallel (1.20.1)
|
|
29
|
+
parser (3.0.2.0)
|
|
30
|
+
ast (~> 2.4.1)
|
|
31
|
+
pry (0.14.1)
|
|
32
|
+
coderay (~> 1.1)
|
|
33
|
+
method_source (~> 1.0)
|
|
35
34
|
rainbow (3.0.0)
|
|
36
|
-
rake (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
rspec-
|
|
41
|
-
|
|
42
|
-
rspec-
|
|
43
|
-
rspec-
|
|
35
|
+
rake (13.0.6)
|
|
36
|
+
regexp_parser (2.1.1)
|
|
37
|
+
rexml (3.2.5)
|
|
38
|
+
rspec (3.10.0)
|
|
39
|
+
rspec-core (~> 3.10.0)
|
|
40
|
+
rspec-expectations (~> 3.10.0)
|
|
41
|
+
rspec-mocks (~> 3.10.0)
|
|
42
|
+
rspec-core (3.10.1)
|
|
43
|
+
rspec-support (~> 3.10.0)
|
|
44
|
+
rspec-expectations (3.10.1)
|
|
44
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
45
|
-
rspec-support (~> 3.
|
|
46
|
-
rspec-mocks (3.
|
|
46
|
+
rspec-support (~> 3.10.0)
|
|
47
|
+
rspec-mocks (3.10.2)
|
|
47
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
48
|
-
rspec-support (~> 3.
|
|
49
|
-
rspec-support (3.
|
|
50
|
-
rubocop (
|
|
51
|
-
jaro_winkler (~> 1.5.1)
|
|
49
|
+
rspec-support (~> 3.10.0)
|
|
50
|
+
rspec-support (3.10.2)
|
|
51
|
+
rubocop (1.18.4)
|
|
52
52
|
parallel (~> 1.10)
|
|
53
|
-
parser (>=
|
|
53
|
+
parser (>= 3.0.0.0)
|
|
54
54
|
rainbow (>= 2.2.2, < 4.0)
|
|
55
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
56
|
+
rexml
|
|
57
|
+
rubocop-ast (>= 1.8.0, < 2.0)
|
|
55
58
|
ruby-progressbar (~> 1.7)
|
|
56
|
-
unicode-display_width (>= 1.4.0, <
|
|
57
|
-
rubocop-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
60
|
+
rubocop-ast (1.8.0)
|
|
61
|
+
parser (>= 3.0.1.1)
|
|
62
|
+
rubocop-rake (0.6.0)
|
|
63
|
+
rubocop (~> 1.0)
|
|
64
|
+
rubocop-rspec (2.4.0)
|
|
65
|
+
rubocop (~> 1.0)
|
|
66
|
+
rubocop-ast (>= 1.1.0)
|
|
67
|
+
ruby-progressbar (1.11.0)
|
|
68
|
+
thor (1.1.0)
|
|
69
|
+
tzinfo (2.0.4)
|
|
70
|
+
concurrent-ruby (~> 1.0)
|
|
71
|
+
unicode-display_width (2.0.0)
|
|
72
|
+
wwtd (1.4.1)
|
|
73
|
+
zeitwerk (2.4.2)
|
|
67
74
|
|
|
68
75
|
PLATFORMS
|
|
69
76
|
ruby
|
|
@@ -76,8 +83,9 @@ DEPENDENCIES
|
|
|
76
83
|
rake
|
|
77
84
|
rspec
|
|
78
85
|
rubocop
|
|
86
|
+
rubocop-rake
|
|
79
87
|
rubocop-rspec
|
|
80
88
|
wwtd
|
|
81
89
|
|
|
82
90
|
BUNDLED WITH
|
|
83
|
-
2.
|
|
91
|
+
2.2.24
|
data/LICENSE
CHANGED
|
@@ -2,7 +2,7 @@ LICENSE
|
|
|
2
2
|
|
|
3
3
|
The MIT License
|
|
4
4
|
|
|
5
|
-
Copyright (c) 2010-
|
|
5
|
+
Copyright (c) 2010-2020 Cássio Marques and Lucas Caton
|
|
6
6
|
|
|
7
7
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
8
8
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Enumerations for Ruby with some magic powers! 🎩
|
|
4
4
|
|
|
5
|
-
[](https://github.com/lucascaton/enumerate_it/actions?query=workflow%3ACI)
|
|
6
6
|
[](https://rubygems.org/gems/enumerate_it)
|
|
7
7
|
[](https://codeclimate.com/github/lucascaton/enumerate_it)
|
|
8
8
|
[](https://rubygems.org/gems/enumerate_it)
|
|
@@ -391,7 +391,7 @@ Remember that you can add validations to any kind of class and not only `ActiveR
|
|
|
391
391
|
|
|
392
392
|
## FAQ
|
|
393
393
|
|
|
394
|
-
#### Why
|
|
394
|
+
#### Why define enumerations outside the class that uses them?
|
|
395
395
|
|
|
396
396
|
* It's clearer.
|
|
397
397
|
* You can add behaviour to the enumeration class.
|
|
@@ -403,11 +403,11 @@ You sure can! 😄
|
|
|
403
403
|
|
|
404
404
|
#### What versions of Ruby and Rails are supported?
|
|
405
405
|
|
|
406
|
-
* **Ruby**: `2.
|
|
407
|
-
* **Rails** `
|
|
406
|
+
* **Ruby**: `2.5+`
|
|
407
|
+
* **Rails** `5.0+`
|
|
408
408
|
|
|
409
409
|
All versions are tested via
|
|
410
|
-
[
|
|
410
|
+
[GitHub Actions](https://github.com/lucascaton/enumerate_it/blob/HEAD/.github/workflows/ci.yml).
|
|
411
411
|
|
|
412
412
|
#### Can I set a value to always be at the end of a sorted list?
|
|
413
413
|
|
|
@@ -528,11 +528,11 @@ Changes are maintained under [Releases page](https://github.com/lucascaton/enume
|
|
|
528
528
|
* Fork the project.
|
|
529
529
|
* Make your feature addition or bug fix.
|
|
530
530
|
* Add tests for it. This is important so we don't break it in a future version unintentionally.
|
|
531
|
-
* [Optional] Run the tests agaist a specific Gemfile: `$ bundle exec appraisal rails_6.
|
|
531
|
+
* [Optional] Run the tests agaist a specific Gemfile: `$ bundle exec appraisal rails_6.1 rake spec`.
|
|
532
532
|
* Run the tests agaist all supported versions: `$ bundle exec rake` (or `$ bundle exec wwtd`)
|
|
533
533
|
* Commit, but please do not mess with `Rakefile`, version, or history.
|
|
534
534
|
* Send a Pull Request. Bonus points for topic branches.
|
|
535
535
|
|
|
536
536
|
## Copyright
|
|
537
537
|
|
|
538
|
-
Copyright (c) 2010-
|
|
538
|
+
Copyright (c) 2010-2021 Cássio Marques and Lucas Caton. See `LICENSE` file for details.
|
data/Rakefile
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
require 'bundler/gem_tasks'
|
|
2
|
+
require 'rspec/core/rake_task'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
Bundler::GemHelper.install_tasks
|
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
RSpec::Core::RakeTask.new(:spec)
|
|
8
|
-
|
|
9
|
-
task default: :spec
|
|
10
|
-
else
|
|
11
|
-
require 'appraisal'
|
|
12
|
-
|
|
13
|
-
task default: :appraisal
|
|
14
|
-
end
|
|
7
|
+
task default: :spec
|
data/enumerate_it.gemspec
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
$LOAD_PATH << File.expand_path('lib', __dir__)
|
|
2
|
+
require 'enumerate_it/version'
|
|
2
3
|
|
|
3
4
|
Gem::Specification.new do |gem|
|
|
4
5
|
gem.authors = ['Cássio Marques', 'Lucas Caton']
|
|
@@ -12,14 +13,14 @@ Gem::Specification.new do |gem|
|
|
|
12
13
|
gem.name = 'enumerate_it'
|
|
13
14
|
gem.require_paths = ['lib']
|
|
14
15
|
gem.version = EnumerateIt::VERSION
|
|
15
|
-
gem.required_ruby_version = '>= 2.
|
|
16
|
+
gem.required_ruby_version = '>= 2.5.8'
|
|
16
17
|
|
|
17
18
|
gem.metadata = {
|
|
18
19
|
'source_code_uri' => 'https://github.com/lucascaton/enumerate_it',
|
|
19
20
|
'changelog_uri' => 'https://github.com/lucascaton/enumerate_it/releases'
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
gem.add_dependency 'activesupport', '>=
|
|
23
|
+
gem.add_dependency 'activesupport', '>= 5.0.7.2'
|
|
23
24
|
|
|
24
25
|
gem.add_development_dependency 'appraisal'
|
|
25
26
|
gem.add_development_dependency 'bundler'
|
|
@@ -27,6 +28,7 @@ Gem::Specification.new do |gem|
|
|
|
27
28
|
gem.add_development_dependency 'rake'
|
|
28
29
|
gem.add_development_dependency 'rspec'
|
|
29
30
|
gem.add_development_dependency 'rubocop'
|
|
31
|
+
gem.add_development_dependency 'rubocop-rake'
|
|
30
32
|
gem.add_development_dependency 'rubocop-rspec'
|
|
31
33
|
gem.add_development_dependency 'wwtd'
|
|
32
34
|
end
|
data/gemfiles/rails_5.1.gemfile
CHANGED
data/gemfiles/rails_5.2.gemfile
CHANGED
data/gemfiles/rails_6.0.gemfile
CHANGED
data/lib/enumerate_it/base.rb
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
require 'forwardable'
|
|
2
|
+
|
|
1
3
|
module EnumerateIt
|
|
2
4
|
class Base
|
|
3
5
|
class << self
|
|
6
|
+
extend Forwardable
|
|
7
|
+
|
|
4
8
|
attr_reader :sort_mode
|
|
5
9
|
|
|
10
|
+
def_delegators :enumeration, :keys, :each_key
|
|
11
|
+
|
|
6
12
|
def associate_values(*args)
|
|
7
13
|
values = values_hash(args)
|
|
8
14
|
|
|
@@ -22,7 +28,7 @@ module EnumerateIt
|
|
|
22
28
|
end
|
|
23
29
|
|
|
24
30
|
def to_h
|
|
25
|
-
sorted_map.
|
|
31
|
+
sorted_map.transform_values(&:first)
|
|
26
32
|
end
|
|
27
33
|
|
|
28
34
|
def enumeration
|
|
@@ -37,16 +43,16 @@ module EnumerateIt
|
|
|
37
43
|
list.length
|
|
38
44
|
end
|
|
39
45
|
|
|
40
|
-
def each_translation
|
|
41
|
-
each_value { |value|
|
|
46
|
+
def each_translation(&block)
|
|
47
|
+
each_value { |value| block.call t(value) }
|
|
42
48
|
end
|
|
43
49
|
|
|
44
50
|
def translations
|
|
45
51
|
list.map { |value| t(value) }
|
|
46
52
|
end
|
|
47
53
|
|
|
48
|
-
def each_value
|
|
49
|
-
list.each
|
|
54
|
+
def each_value(&block)
|
|
55
|
+
list.each(&block)
|
|
50
56
|
end
|
|
51
57
|
|
|
52
58
|
def to_json(options = nil)
|
|
@@ -63,7 +69,7 @@ module EnumerateIt
|
|
|
63
69
|
end
|
|
64
70
|
|
|
65
71
|
def value_for(value)
|
|
66
|
-
const_get(value.to_sym)
|
|
72
|
+
const_get(value.to_sym, false)
|
|
67
73
|
rescue NameError
|
|
68
74
|
nil
|
|
69
75
|
end
|
|
@@ -74,10 +80,6 @@ module EnumerateIt
|
|
|
74
80
|
(enumeration[key.to_sym] || []).first
|
|
75
81
|
end
|
|
76
82
|
|
|
77
|
-
def keys
|
|
78
|
-
enumeration.keys
|
|
79
|
-
end
|
|
80
|
-
|
|
81
83
|
def key_for(value)
|
|
82
84
|
enumeration.map { |e| e[0] if e[1][0] == value }.compact.first
|
|
83
85
|
end
|
data/lib/enumerate_it/version.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe EnumerateIt::Base do
|
|
4
4
|
it 'creates constants for each enumeration value' do
|
|
@@ -85,6 +85,16 @@ describe EnumerateIt::Base do
|
|
|
85
85
|
end
|
|
86
86
|
end
|
|
87
87
|
|
|
88
|
+
describe '.each_key' do
|
|
89
|
+
it "yields each enumeration's key" do
|
|
90
|
+
keys = []
|
|
91
|
+
TestEnumeration.each_key do |key|
|
|
92
|
+
keys << key
|
|
93
|
+
end
|
|
94
|
+
expect(keys).to eq(%i[value_1 value_2 value_3])
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
88
98
|
describe '.each_value' do
|
|
89
99
|
it "yields each enumeration's value" do
|
|
90
100
|
values = []
|
|
@@ -168,6 +178,12 @@ describe EnumerateIt::Base do
|
|
|
168
178
|
expect(TestEnumeration.value_for('THIS_IS_WRONG')).to be_nil
|
|
169
179
|
end
|
|
170
180
|
end
|
|
181
|
+
|
|
182
|
+
context 'when a constant named after the received value exists as an ancestor' do
|
|
183
|
+
it 'returns nil' do
|
|
184
|
+
expect(TestEnumeration.value_for('Module')).to be_nil
|
|
185
|
+
end
|
|
186
|
+
end
|
|
171
187
|
end
|
|
172
188
|
|
|
173
189
|
describe '.value_from_key' do
|
data/spec/enumerate_it_spec.rb
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe EnumerateIt do
|
|
4
4
|
let :test_class do
|
|
5
5
|
Class.new do
|
|
6
6
|
extend EnumerateIt
|
|
7
7
|
attr_accessor :foobar
|
|
8
|
+
|
|
8
9
|
has_enumeration_for :foobar, with: TestEnumeration
|
|
9
10
|
|
|
10
11
|
def initialize(foobar)
|
|
@@ -62,6 +63,7 @@ describe EnumerateIt do
|
|
|
62
63
|
Class.new do
|
|
63
64
|
extend EnumerateIt
|
|
64
65
|
attr_accessor :foobar
|
|
66
|
+
|
|
65
67
|
has_enumeration_for :foobar, with: TestEnumerationWithoutArray
|
|
66
68
|
|
|
67
69
|
def initialize(foobar)
|
|
@@ -92,6 +94,7 @@ describe EnumerateIt do
|
|
|
92
94
|
Class.new do
|
|
93
95
|
extend EnumerateIt
|
|
94
96
|
attr_accessor :test_enumeration
|
|
97
|
+
|
|
95
98
|
has_enumeration_for :test_enumeration
|
|
96
99
|
|
|
97
100
|
def initialize(test_enumeration_value)
|
|
@@ -109,14 +112,17 @@ describe EnumerateIt do
|
|
|
109
112
|
context 'when using a nested class as the enumeration' do
|
|
110
113
|
let :class_with_nested_enum do
|
|
111
114
|
Class.new do
|
|
115
|
+
# rubocop:disable Lint/ConstantDefinitionInBlock
|
|
112
116
|
# rubocop:disable RSpec/LeakyConstantDeclaration
|
|
113
117
|
class NestedEnum < EnumerateIt::Base
|
|
114
118
|
associate_values foo: %w[1 Blerrgh], bar: ['2' => 'Blarghhh']
|
|
115
119
|
end
|
|
116
120
|
# rubocop:enable RSpec/LeakyConstantDeclaration
|
|
121
|
+
# rubocop:enable Lint/ConstantDefinitionInBlock
|
|
117
122
|
|
|
118
123
|
extend EnumerateIt
|
|
119
124
|
attr_accessor :nested_enum
|
|
125
|
+
|
|
120
126
|
has_enumeration_for :nested_enum
|
|
121
127
|
|
|
122
128
|
def initialize(nested_enum_value)
|
|
@@ -137,6 +143,7 @@ describe EnumerateIt do
|
|
|
137
143
|
Class.new do
|
|
138
144
|
extend EnumerateIt
|
|
139
145
|
attr_accessor :foobar
|
|
146
|
+
|
|
140
147
|
has_enumeration_for :foobar, with: TestEnumeration, create_helpers: true
|
|
141
148
|
|
|
142
149
|
def initialize(foobar)
|
|
@@ -177,6 +184,7 @@ describe EnumerateIt do
|
|
|
177
184
|
Class.new do
|
|
178
185
|
extend EnumerateIt
|
|
179
186
|
attr_accessor :foobar
|
|
187
|
+
|
|
180
188
|
has_enumeration_for :foobar, with: TestEnumeration, create_helpers: { prefix: true }
|
|
181
189
|
|
|
182
190
|
def initialize(foobar)
|
|
@@ -218,6 +226,7 @@ describe EnumerateIt do
|
|
|
218
226
|
Class.new do
|
|
219
227
|
extend EnumerateIt
|
|
220
228
|
attr_accessor :foo
|
|
229
|
+
|
|
221
230
|
has_enumeration_for :foo, with: PolymorphicEnum, create_helpers: { polymorphic: true }
|
|
222
231
|
end
|
|
223
232
|
end
|
|
@@ -243,6 +252,7 @@ describe EnumerateIt do
|
|
|
243
252
|
Class.new do
|
|
244
253
|
extend EnumerateIt
|
|
245
254
|
attr_accessor :foo
|
|
255
|
+
|
|
246
256
|
has_enumeration_for :foo, with: PolymorphicEnum,
|
|
247
257
|
create_helpers: { polymorphic: { suffix: '_strategy' } }
|
|
248
258
|
end
|
|
@@ -283,7 +293,7 @@ describe EnumerateIt do
|
|
|
283
293
|
|
|
284
294
|
TestEnumeration.enumeration.each do |symbol, pair|
|
|
285
295
|
expect(test_class_with_scope.public_send(symbol).to_sql)
|
|
286
|
-
.to match(/WHERE "test_class_with_scopes"."foobar" =
|
|
296
|
+
.to match(/WHERE "test_class_with_scopes"."foobar" = '#{pair.first}'/)
|
|
287
297
|
end
|
|
288
298
|
end
|
|
289
299
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -5,7 +5,7 @@ require 'enumerate_it'
|
|
|
5
5
|
require 'active_support/all'
|
|
6
6
|
require 'active_record'
|
|
7
7
|
|
|
8
|
-
Dir['./spec/support/**/*.rb'].each { |f| require f }
|
|
8
|
+
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
|
|
9
9
|
|
|
10
10
|
I18n.config.enforce_available_locales = false
|
|
11
11
|
I18n.load_path = Dir['spec/i18n/*.yml']
|
metadata
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: enumerate_it
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cássio Marques
|
|
8
8
|
- Lucas Caton
|
|
9
|
-
autorequire:
|
|
9
|
+
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2021-08-05 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|
|
@@ -17,14 +17,14 @@ dependencies:
|
|
|
17
17
|
requirements:
|
|
18
18
|
- - ">="
|
|
19
19
|
- !ruby/object:Gem::Version
|
|
20
|
-
version:
|
|
20
|
+
version: 5.0.7.2
|
|
21
21
|
type: :runtime
|
|
22
22
|
prerelease: false
|
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
24
24
|
requirements:
|
|
25
25
|
- - ">="
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
|
-
version:
|
|
27
|
+
version: 5.0.7.2
|
|
28
28
|
- !ruby/object:Gem::Dependency
|
|
29
29
|
name: appraisal
|
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -109,6 +109,20 @@ dependencies:
|
|
|
109
109
|
- - ">="
|
|
110
110
|
- !ruby/object:Gem::Version
|
|
111
111
|
version: '0'
|
|
112
|
+
- !ruby/object:Gem::Dependency
|
|
113
|
+
name: rubocop-rake
|
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
|
115
|
+
requirements:
|
|
116
|
+
- - ">="
|
|
117
|
+
- !ruby/object:Gem::Version
|
|
118
|
+
version: '0'
|
|
119
|
+
type: :development
|
|
120
|
+
prerelease: false
|
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
122
|
+
requirements:
|
|
123
|
+
- - ">="
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: '0'
|
|
112
126
|
- !ruby/object:Gem::Dependency
|
|
113
127
|
name: rubocop-rspec
|
|
114
128
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -138,15 +152,15 @@ dependencies:
|
|
|
138
152
|
- !ruby/object:Gem::Version
|
|
139
153
|
version: '0'
|
|
140
154
|
description: Enumerations for Ruby with some magic powers!
|
|
141
|
-
email:
|
|
155
|
+
email:
|
|
142
156
|
executables: []
|
|
143
157
|
extensions: []
|
|
144
158
|
extra_rdoc_files: []
|
|
145
159
|
files:
|
|
160
|
+
- ".github/workflows/ci.yml"
|
|
146
161
|
- ".gitignore"
|
|
147
162
|
- ".rspec"
|
|
148
163
|
- ".rubocop.yml"
|
|
149
|
-
- ".travis.yml"
|
|
150
164
|
- Appraisals
|
|
151
165
|
- CHANGELOG.md
|
|
152
166
|
- Gemfile
|
|
@@ -155,11 +169,11 @@ files:
|
|
|
155
169
|
- README.md
|
|
156
170
|
- Rakefile
|
|
157
171
|
- enumerate_it.gemspec
|
|
158
|
-
- gemfiles/rails_4.2.gemfile
|
|
159
172
|
- gemfiles/rails_5.0.gemfile
|
|
160
173
|
- gemfiles/rails_5.1.gemfile
|
|
161
174
|
- gemfiles/rails_5.2.gemfile
|
|
162
175
|
- gemfiles/rails_6.0.gemfile
|
|
176
|
+
- gemfiles/rails_6.1.gemfile
|
|
163
177
|
- lib/enumerate_it.rb
|
|
164
178
|
- lib/enumerate_it/base.rb
|
|
165
179
|
- lib/enumerate_it/class_methods.rb
|
|
@@ -180,7 +194,7 @@ licenses:
|
|
|
180
194
|
metadata:
|
|
181
195
|
source_code_uri: https://github.com/lucascaton/enumerate_it
|
|
182
196
|
changelog_uri: https://github.com/lucascaton/enumerate_it/releases
|
|
183
|
-
post_install_message:
|
|
197
|
+
post_install_message:
|
|
184
198
|
rdoc_options: []
|
|
185
199
|
require_paths:
|
|
186
200
|
- lib
|
|
@@ -188,15 +202,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
188
202
|
requirements:
|
|
189
203
|
- - ">="
|
|
190
204
|
- !ruby/object:Gem::Version
|
|
191
|
-
version: 2.
|
|
205
|
+
version: 2.5.8
|
|
192
206
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
207
|
requirements:
|
|
194
208
|
- - ">="
|
|
195
209
|
- !ruby/object:Gem::Version
|
|
196
210
|
version: '0'
|
|
197
211
|
requirements: []
|
|
198
|
-
rubygems_version: 3.
|
|
199
|
-
signing_key:
|
|
212
|
+
rubygems_version: 3.2.25
|
|
213
|
+
signing_key:
|
|
200
214
|
specification_version: 4
|
|
201
215
|
summary: Ruby Enumerations
|
|
202
216
|
test_files:
|
data/.travis.yml
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
language: ruby
|
|
2
|
-
|
|
3
|
-
sudo: false
|
|
4
|
-
|
|
5
|
-
cache: bundler
|
|
6
|
-
|
|
7
|
-
script:
|
|
8
|
-
- "ruby -e \"RUBY_VERSION == '2.6.4' ? system('bundle exec rubocop') : exit(0)\""
|
|
9
|
-
- bundle exec rake spec
|
|
10
|
-
|
|
11
|
-
rvm:
|
|
12
|
-
- 2.4.7
|
|
13
|
-
- 2.5.6
|
|
14
|
-
- 2.6.4
|
|
15
|
-
|
|
16
|
-
gemfile:
|
|
17
|
-
- gemfiles/rails_4.2.gemfile
|
|
18
|
-
- gemfiles/rails_5.0.gemfile
|
|
19
|
-
- gemfiles/rails_5.1.gemfile
|
|
20
|
-
- gemfiles/rails_5.2.gemfile
|
|
21
|
-
- gemfiles/rails_6.0.gemfile
|
|
22
|
-
|
|
23
|
-
matrix:
|
|
24
|
-
exclude:
|
|
25
|
-
# Rails 6 requires Ruby 2.5+
|
|
26
|
-
- rvm: 2.4.7
|
|
27
|
-
gemfile: gemfiles/rails_6.0.gemfile
|
|
28
|
-
|
|
29
|
-
addons:
|
|
30
|
-
code_climate:
|
|
31
|
-
repo_token: 60e4a18e2a4bc86a98f92847f16756876c13d1e772058a9b3296643b04a697d7
|