ruby-enum 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -10
- data/Dangerfile +4 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +89 -9
- data/LICENSE.md +1 -1
- data/README.md +143 -76
- data/RELEASING.md +4 -11
- data/UPGRADING.md +44 -0
- data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc.png +0 -0
- data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc_disabled.png +0 -0
- data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_both.png +0 -0
- data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc.png +0 -0
- data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc_disabled.png +0 -0
- data/coverage/assets/0.12.3/application.css +1 -0
- data/coverage/assets/0.12.3/application.js +7 -0
- data/coverage/assets/0.12.3/colorbox/border.png +0 -0
- data/coverage/assets/0.12.3/colorbox/controls.png +0 -0
- data/coverage/assets/0.12.3/colorbox/loading.gif +0 -0
- data/coverage/assets/0.12.3/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.12.3/favicon_green.png +0 -0
- data/coverage/assets/0.12.3/favicon_red.png +0 -0
- data/coverage/assets/0.12.3/favicon_yellow.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.12.3/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.12.3/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.12.3/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.12.3/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.12.3/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/assets/0.12.3/loading.gif +0 -0
- data/coverage/assets/0.12.3/magnify.png +0 -0
- data/coverage/index.html +3841 -0
- data/lib/ruby-enum/enum.rb +8 -2
- data/lib/ruby-enum/errors/base.rb +1 -1
- data/lib/ruby-enum/version.rb +1 -1
- data/pkg/ruby-enum-0.8.0.gem +0 -0
- data/spec/ruby-enum/enum_spec.rb +37 -0
- data/spec/spec_helper.rb +4 -0
- metadata +39 -6
data/lib/ruby-enum/enum.rb
CHANGED
@@ -22,7 +22,7 @@ module Ruby
|
|
22
22
|
# === Parameters
|
23
23
|
# [key] Enumerator key.
|
24
24
|
# [value] Enumerator value.
|
25
|
-
def define(key, value)
|
25
|
+
def define(key, value = key)
|
26
26
|
@_enum_hash ||= {}
|
27
27
|
@_enums_by_value ||= {}
|
28
28
|
|
@@ -118,7 +118,13 @@ module Ruby
|
|
118
118
|
|
119
119
|
# Returns all enum values.
|
120
120
|
def values
|
121
|
-
@_enum_hash.values.map(&:value)
|
121
|
+
result = @_enum_hash.values.map(&:value)
|
122
|
+
|
123
|
+
if superclass < Ruby::Enum
|
124
|
+
superclass.values + result
|
125
|
+
else
|
126
|
+
result
|
127
|
+
end
|
122
128
|
end
|
123
129
|
|
124
130
|
# Iterate over all enumerated values.
|
@@ -39,7 +39,7 @@ module Ruby
|
|
39
39
|
#
|
40
40
|
# Returns a localized error message string.
|
41
41
|
def translate(key, options)
|
42
|
-
::I18n.translate("#{BASE_KEY}.#{key}", { locale: :en }.merge(options)).strip
|
42
|
+
::I18n.translate("#{BASE_KEY}.#{key}", **{ locale: :en }.merge(options)).strip
|
43
43
|
end
|
44
44
|
|
45
45
|
# Create the problem.
|
data/lib/ruby-enum/version.rb
CHANGED
Binary file
|
data/spec/ruby-enum/enum_spec.rb
CHANGED
@@ -187,6 +187,35 @@ describe Ruby::Enum do
|
|
187
187
|
expect(subject::ORANGE).to eq 'orange'
|
188
188
|
expect(subject::PINK).to eq 'pink'
|
189
189
|
end
|
190
|
+
|
191
|
+
describe '#values' do
|
192
|
+
subject { SecondSubclass.values }
|
193
|
+
|
194
|
+
it 'contains the values from all of the parent classes' do
|
195
|
+
expect(subject).to eq(%w[red green orange pink])
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe '#values' do
|
201
|
+
subject { FirstSubclass.values }
|
202
|
+
|
203
|
+
it 'contains the values from the parent class' do
|
204
|
+
expect(subject).to eq(%w[red green orange])
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe 'default value' do
|
210
|
+
class Default
|
211
|
+
include Ruby::Enum
|
212
|
+
define :KEY
|
213
|
+
end
|
214
|
+
|
215
|
+
subject { Default::KEY }
|
216
|
+
|
217
|
+
it 'equals the key' do
|
218
|
+
expect(subject).to eq(:KEY)
|
190
219
|
end
|
191
220
|
end
|
192
221
|
|
@@ -195,17 +224,25 @@ describe Ruby::Enum do
|
|
195
224
|
include Ruby::Enum
|
196
225
|
define :created, 'Created'
|
197
226
|
define :published, 'Published'
|
227
|
+
define :undefined
|
198
228
|
end
|
199
229
|
subject { States }
|
200
230
|
it 'behaves like an enum' do
|
201
231
|
expect(subject.created).to eq 'Created'
|
202
232
|
expect(subject.published).to eq 'Published'
|
233
|
+
expect(subject.undefined).to eq :undefined
|
203
234
|
|
204
235
|
expect(subject.key?(:created)).to be true
|
205
236
|
expect(subject.key('Created')).to eq :created
|
206
237
|
|
207
238
|
expect(subject.value?('Created')).to be true
|
208
239
|
expect(subject.value(:created)).to eq 'Created'
|
240
|
+
|
241
|
+
expect(subject.key?(:undefined)).to be true
|
242
|
+
expect(subject.key(:undefined)).to eq :undefined
|
243
|
+
|
244
|
+
expect(subject.value?(:undefined)).to be true
|
245
|
+
expect(subject.value(:undefined)).to eq :undefined
|
209
246
|
end
|
210
247
|
end
|
211
248
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email: dblock@dblock.org
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
@@ -32,12 +32,44 @@ extra_rdoc_files: []
|
|
32
32
|
files:
|
33
33
|
- CHANGELOG.md
|
34
34
|
- CONTRIBUTING.md
|
35
|
+
- Dangerfile
|
35
36
|
- Gemfile
|
36
37
|
- Gemfile.lock
|
37
38
|
- LICENSE.md
|
38
39
|
- README.md
|
39
40
|
- RELEASING.md
|
40
41
|
- Rakefile
|
42
|
+
- UPGRADING.md
|
43
|
+
- coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc.png
|
44
|
+
- coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc_disabled.png
|
45
|
+
- coverage/assets/0.12.3/DataTables-1.10.20/images/sort_both.png
|
46
|
+
- coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc.png
|
47
|
+
- coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc_disabled.png
|
48
|
+
- coverage/assets/0.12.3/application.css
|
49
|
+
- coverage/assets/0.12.3/application.js
|
50
|
+
- coverage/assets/0.12.3/colorbox/border.png
|
51
|
+
- coverage/assets/0.12.3/colorbox/controls.png
|
52
|
+
- coverage/assets/0.12.3/colorbox/loading.gif
|
53
|
+
- coverage/assets/0.12.3/colorbox/loading_background.png
|
54
|
+
- coverage/assets/0.12.3/favicon_green.png
|
55
|
+
- coverage/assets/0.12.3/favicon_red.png
|
56
|
+
- coverage/assets/0.12.3/favicon_yellow.png
|
57
|
+
- coverage/assets/0.12.3/images/ui-bg_flat_0_aaaaaa_40x100.png
|
58
|
+
- coverage/assets/0.12.3/images/ui-bg_flat_75_ffffff_40x100.png
|
59
|
+
- coverage/assets/0.12.3/images/ui-bg_glass_55_fbf9ee_1x400.png
|
60
|
+
- coverage/assets/0.12.3/images/ui-bg_glass_65_ffffff_1x400.png
|
61
|
+
- coverage/assets/0.12.3/images/ui-bg_glass_75_dadada_1x400.png
|
62
|
+
- coverage/assets/0.12.3/images/ui-bg_glass_75_e6e6e6_1x400.png
|
63
|
+
- coverage/assets/0.12.3/images/ui-bg_glass_95_fef1ec_1x400.png
|
64
|
+
- coverage/assets/0.12.3/images/ui-bg_highlight-soft_75_cccccc_1x100.png
|
65
|
+
- coverage/assets/0.12.3/images/ui-icons_222222_256x240.png
|
66
|
+
- coverage/assets/0.12.3/images/ui-icons_2e83ff_256x240.png
|
67
|
+
- coverage/assets/0.12.3/images/ui-icons_454545_256x240.png
|
68
|
+
- coverage/assets/0.12.3/images/ui-icons_888888_256x240.png
|
69
|
+
- coverage/assets/0.12.3/images/ui-icons_cd0a0a_256x240.png
|
70
|
+
- coverage/assets/0.12.3/loading.gif
|
71
|
+
- coverage/assets/0.12.3/magnify.png
|
72
|
+
- coverage/index.html
|
41
73
|
- lib/config/locales/en.yml
|
42
74
|
- lib/ruby-enum.rb
|
43
75
|
- lib/ruby-enum/enum.rb
|
@@ -47,6 +79,7 @@ files:
|
|
47
79
|
- lib/ruby-enum/errors/uninitialized_constant_error.rb
|
48
80
|
- lib/ruby-enum/version.rb
|
49
81
|
- lib/ruby_enum.rb
|
82
|
+
- pkg/ruby-enum-0.8.0.gem
|
50
83
|
- ruby-enum.gemspec
|
51
84
|
- spec/ruby-enum/enum_spec.rb
|
52
85
|
- spec/ruby-enum/version_spec.rb
|
@@ -55,7 +88,7 @@ homepage: http://github.com/dblock/ruby-enum
|
|
55
88
|
licenses:
|
56
89
|
- MIT
|
57
90
|
metadata: {}
|
58
|
-
post_install_message:
|
91
|
+
post_install_message:
|
59
92
|
rdoc_options: []
|
60
93
|
require_paths:
|
61
94
|
- lib
|
@@ -71,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
104
|
version: 1.3.6
|
72
105
|
requirements: []
|
73
106
|
rubygems_version: 3.0.3
|
74
|
-
signing_key:
|
107
|
+
signing_key:
|
75
108
|
specification_version: 4
|
76
109
|
summary: Enum-like behavior for Ruby.
|
77
110
|
test_files: []
|