enumerate_it 1.2.9 → 1.3.0
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/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +1 -1
- data/Gemfile.lock +29 -10
- data/LICENSE +1 -1
- data/README.md +16 -4
- data/enumerate_it.gemspec +2 -2
- data/lib/enumerate_it/base.rb +8 -10
- data/lib/enumerate_it/class_methods.rb +7 -3
- data/lib/enumerate_it/version.rb +1 -1
- data/lib/generators/enumerate_it/enum/enum_generator.rb +3 -3
- data/spec/enumerate_it/base_spec.rb +73 -55
- data/spec/enumerate_it_spec.rb +73 -66
- data/spec/spec_helper.rb +4 -3
- data/spec/support/test_classes.rb +14 -15
- metadata +21 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eeb5e0de6df61f17293c7d0c7b5d833c5d3738b3
|
4
|
+
data.tar.gz: 31978fd7c1d78bbcf499ecf4c6d66f3101add5a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 910befeeabdbd3647ca2b1c7c9115cee8e8bd927fd938dac4704a03a6b0cf077524e17a604edf2fb31d5493b6d4aec6819cfbec0e46b51d16a633b0974903af2
|
7
|
+
data.tar.gz: cf9b34ec103040023ac449a9fecffad45a3bca529f3ae041683838fbd25f23f48cce1dda40c5aeae9ccddc7388aa3a9058353b1e985d533a339b09a12105854e
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.3.1
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
enumerate_it (1.
|
4
|
+
enumerate_it (1.3.0)
|
5
5
|
activesupport (>= 3.0.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -17,30 +17,48 @@ GEM
|
|
17
17
|
bundler
|
18
18
|
rake
|
19
19
|
thor (>= 0.14.0)
|
20
|
+
ast (2.2.0)
|
20
21
|
coderay (1.0.9)
|
21
22
|
diff-lcs (1.2.5)
|
22
23
|
i18n (0.7.0)
|
23
24
|
json (1.8.3)
|
24
25
|
method_source (0.8.1)
|
25
26
|
minitest (5.8.4)
|
27
|
+
parser (2.3.0.7)
|
28
|
+
ast (~> 2.2)
|
29
|
+
powerpack (0.1.1)
|
26
30
|
pry (0.9.12)
|
27
31
|
coderay (~> 1.0.5)
|
28
32
|
method_source (~> 0.8)
|
29
33
|
slop (~> 3.4)
|
34
|
+
rainbow (2.1.0)
|
30
35
|
rake (11.1.1)
|
31
|
-
rspec (
|
32
|
-
rspec-core (~>
|
33
|
-
rspec-expectations (~>
|
34
|
-
rspec-mocks (~>
|
35
|
-
rspec-core (
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
rspec (3.4.0)
|
37
|
+
rspec-core (~> 3.4.0)
|
38
|
+
rspec-expectations (~> 3.4.0)
|
39
|
+
rspec-mocks (~> 3.4.0)
|
40
|
+
rspec-core (3.4.1)
|
41
|
+
rspec-support (~> 3.4.0)
|
42
|
+
rspec-expectations (3.4.0)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.4.0)
|
45
|
+
rspec-mocks (3.4.0)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.4.0)
|
48
|
+
rspec-support (3.4.1)
|
49
|
+
rubocop (0.38.0)
|
50
|
+
parser (>= 2.3.0.6, < 3.0)
|
51
|
+
powerpack (~> 0.1)
|
52
|
+
rainbow (>= 1.99.1, < 3.0)
|
53
|
+
ruby-progressbar (~> 1.7)
|
54
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
55
|
+
ruby-progressbar (1.7.5)
|
39
56
|
slop (3.4.4)
|
40
57
|
thor (0.19.1)
|
41
58
|
thread_safe (0.3.5)
|
42
59
|
tzinfo (1.2.2)
|
43
60
|
thread_safe (~> 0.1)
|
61
|
+
unicode-display_width (1.0.2)
|
44
62
|
|
45
63
|
PLATFORMS
|
46
64
|
ruby
|
@@ -50,7 +68,8 @@ DEPENDENCIES
|
|
50
68
|
enumerate_it!
|
51
69
|
pry
|
52
70
|
rake
|
53
|
-
rspec
|
71
|
+
rspec
|
72
|
+
rubocop
|
54
73
|
|
55
74
|
BUNDLED WITH
|
56
75
|
1.11.2
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -172,9 +172,9 @@ You can also create enumerations in the following ways:
|
|
172
172
|
|
173
173
|
### Defining a default sort mode
|
174
174
|
|
175
|
-
When calling methods like `to_a` and `
|
176
|
-
sorted using the translation for each one of the enumeration values.
|
177
|
-
want to overwrite the default sort mode, you can use the `sort_by` class
|
175
|
+
When calling methods like `to_a`, `to_json` and `list`, the returned values
|
176
|
+
will be sorted using the translation for each one of the enumeration values.
|
177
|
+
If you want to overwrite the default sort mode, you can use the `sort_by` class
|
178
178
|
method.
|
179
179
|
|
180
180
|
```ruby
|
@@ -405,6 +405,18 @@ This will create:
|
|
405
405
|
#=> "can't be blank"
|
406
406
|
```
|
407
407
|
|
408
|
+
* If you pass the `:skip_validation` option as `true`, it will not create any validations:
|
409
|
+
|
410
|
+
```ruby
|
411
|
+
class Person < ActiveRecord::Base
|
412
|
+
has_enumeration_for :relationship_status, with: RelationshipStatus, skip_validation: true
|
413
|
+
end
|
414
|
+
|
415
|
+
p = Person.new(relationship_status: 1_000_000)
|
416
|
+
p.valid?
|
417
|
+
#=> true
|
418
|
+
```
|
419
|
+
|
408
420
|
Remember that you can add validations to any kind of class and not only to
|
409
421
|
those derived from ActiveRecord::Base.
|
410
422
|
|
@@ -482,7 +494,7 @@ their locale files. Take a look at how to use it running:
|
|
482
494
|
rails generate enumerate_it:enum --help
|
483
495
|
```
|
484
496
|
|
485
|
-
## Supported versions
|
497
|
+
## Supported Ruby and Rails (ActiveSupport) versions
|
486
498
|
|
487
499
|
Check [travis config file](https://github.com/lucascaton/enumerate_it/blob/master/.travis.yml).
|
488
500
|
|
data/enumerate_it.gemspec
CHANGED
@@ -6,7 +6,6 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.summary = 'Ruby Enumerations'
|
7
7
|
gem.homepage = 'https://github.com/lucascaton/enumerate_it'
|
8
8
|
|
9
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
10
9
|
gem.files = `git ls-files`.split("\n")
|
11
10
|
gem.test_files = `git ls-files -- spec/*`.split("\n")
|
12
11
|
gem.name = 'enumerate_it'
|
@@ -18,5 +17,6 @@ Gem::Specification.new do |gem|
|
|
18
17
|
gem.add_development_dependency 'appraisal'
|
19
18
|
gem.add_development_dependency 'pry'
|
20
19
|
gem.add_development_dependency 'rake'
|
21
|
-
gem.add_development_dependency 'rspec'
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
gem.add_development_dependency 'rubocop'
|
22
22
|
end
|
data/lib/enumerate_it/base.rb
CHANGED
@@ -27,7 +27,7 @@ module EnumerateIt
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.to_a
|
30
|
-
sorted_map.map { |
|
30
|
+
sorted_map.map { |_k, v| [translate(v[1]), v[0]] }
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.length
|
@@ -47,7 +47,7 @@ module EnumerateIt
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def self.to_json
|
50
|
-
sorted_map.map { |
|
50
|
+
sorted_map.map { |_k, v| { value: v[0], label: translate(v[1]) } }.to_json
|
51
51
|
end
|
52
52
|
|
53
53
|
def self.t(value)
|
@@ -75,7 +75,7 @@ module EnumerateIt
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def self.key_for(value)
|
78
|
-
enumeration.map {|e| e[0] if e[1][0] == value }.compact.first
|
78
|
+
enumeration.map { |e| e[0] if e[1][0] == value }.compact.first
|
79
79
|
end
|
80
80
|
|
81
81
|
def self.to_range
|
@@ -92,9 +92,9 @@ module EnumerateIt
|
|
92
92
|
|
93
93
|
def self.sort_lambda
|
94
94
|
{
|
95
|
-
:
|
96
|
-
:
|
97
|
-
:
|
95
|
+
value: lambda { |_k, v| v[0] },
|
96
|
+
name: lambda { |k, _v| k },
|
97
|
+
translation: lambda { |_k, v| translate(v[1]) }
|
98
98
|
}[sort_mode || :translation]
|
99
99
|
end
|
100
100
|
|
@@ -102,14 +102,12 @@ module EnumerateIt
|
|
102
102
|
return value unless value.is_a? Symbol
|
103
103
|
|
104
104
|
default = value.to_s.gsub(/_/, ' ').split.map(&:capitalize).join(' ')
|
105
|
-
I18n.t("enumerations.#{self.name.underscore}.#{value.to_s.underscore}", :
|
105
|
+
I18n.t("enumerations.#{self.name.underscore}.#{value.to_s.underscore}", default: default)
|
106
106
|
end
|
107
107
|
|
108
108
|
def self.normalize_enumeration(values_hash)
|
109
109
|
values_hash.each_pair do |key, value|
|
110
|
-
unless value.is_a? Array
|
111
|
-
values_hash[key] = [value, key]
|
112
|
-
end
|
110
|
+
values_hash[key] = [value, key] unless value.is_a? Array
|
113
111
|
end
|
114
112
|
end
|
115
113
|
|
@@ -5,10 +5,13 @@ module EnumerateIt
|
|
5
5
|
self.enumerations = self.enumerations.dup
|
6
6
|
|
7
7
|
define_enumeration_class attribute, options
|
8
|
-
set_validations attribute, options
|
9
8
|
create_enumeration_humanize_method options[:with], attribute
|
10
9
|
store_enumeration options[:with], attribute
|
11
10
|
|
11
|
+
unless options[:skip_validation]
|
12
|
+
set_validations attribute, options
|
13
|
+
end
|
14
|
+
|
12
15
|
if options[:create_helpers]
|
13
16
|
create_helper_methods options[:with], attribute, options[:create_helpers]
|
14
17
|
create_mutator_methods options[:with], attribute, options[:create_helpers]
|
@@ -21,6 +24,7 @@ module EnumerateIt
|
|
21
24
|
end
|
22
25
|
|
23
26
|
private
|
27
|
+
|
24
28
|
def store_enumeration(klass, attribute)
|
25
29
|
enumerations[attribute] = klass
|
26
30
|
end
|
@@ -52,7 +56,7 @@ module EnumerateIt
|
|
52
56
|
|
53
57
|
klass.enumeration.keys.each do |key|
|
54
58
|
if respond_to? :scope
|
55
|
-
scope "#{prefix_name}#{key}", lambda { where(attribute_name => klass.enumeration[key].first)}
|
59
|
+
scope "#{prefix_name}#{key}", lambda { where(attribute_name => klass.enumeration[key].first) }
|
56
60
|
end
|
57
61
|
end
|
58
62
|
end
|
@@ -92,7 +96,7 @@ module EnumerateIt
|
|
92
96
|
end
|
93
97
|
|
94
98
|
def set_validations(attribute, options)
|
95
|
-
validates_inclusion_of(attribute, :
|
99
|
+
validates_inclusion_of(attribute, in: options[:with].list, allow_blank: true) if self.respond_to?(:validates_inclusion_of)
|
96
100
|
|
97
101
|
if options[:required] && respond_to?(:validates_presence_of)
|
98
102
|
opts = options[:required].is_a?(Hash) ? options[:required] : {}
|
data/lib/enumerate_it/version.rb
CHANGED
@@ -3,11 +3,11 @@ module EnumerateIt
|
|
3
3
|
class EnumGenerator < Rails::Generators::NamedBase
|
4
4
|
source_root File.expand_path('../templates', __FILE__)
|
5
5
|
|
6
|
-
argument :attributes, :
|
6
|
+
argument :attributes, type: 'array', default: []
|
7
7
|
|
8
|
-
class_option :singular, :
|
8
|
+
class_option :singular, type: 'string', desc: 'Singular name for i18n'
|
9
9
|
|
10
|
-
class_option :lang, :
|
10
|
+
class_option :lang, type: 'string', desc: 'Lang to use in i18n', default: 'en'
|
11
11
|
|
12
12
|
desc "Creates a locale file on config/locales"
|
13
13
|
def create_locale
|
@@ -1,24 +1,25 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
|
2
3
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
4
|
|
4
5
|
describe EnumerateIt::Base do
|
5
6
|
it "creates constants for each enumeration value" do
|
6
7
|
[TestEnumeration::VALUE_1, TestEnumeration::VALUE_2, TestEnumeration::VALUE_3].each_with_index do |constant, idx|
|
7
|
-
constant.
|
8
|
+
expect(constant).to eq((idx + 1).to_s)
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
11
12
|
it "creates constants for camel case values" do
|
12
|
-
TestEnumerationWithCamelCase::IPHONE.
|
13
|
+
expect(TestEnumerationWithCamelCase::IPHONE).to eq('iPhone')
|
13
14
|
end
|
14
15
|
|
15
16
|
it "creates constants replacing its dashes with underscores" do
|
16
|
-
TestEnumerationWithDash::PT_BR.
|
17
|
+
expect(TestEnumerationWithDash::PT_BR).to eq('pt-BR')
|
17
18
|
end
|
18
19
|
|
19
20
|
describe ".list" do
|
20
21
|
it "creates a method that returns the allowed values in the enumeration's class" do
|
21
|
-
TestEnumeration.list.
|
22
|
+
expect(TestEnumeration.list).to eq(['1', '2', '3'])
|
22
23
|
end
|
23
24
|
|
24
25
|
context "specifying a default sort mode" do
|
@@ -27,40 +28,40 @@ describe EnumerateIt::Base do
|
|
27
28
|
context "by value" do
|
28
29
|
let(:sort_mode) { :value }
|
29
30
|
|
30
|
-
it { should
|
31
|
+
it { should eq(%w(0 1 2 3)) }
|
31
32
|
end
|
32
33
|
|
33
34
|
context "by name" do
|
34
35
|
let(:sort_mode) { :name }
|
35
36
|
|
36
|
-
it { should
|
37
|
+
it { should eq(%w(2 1 3 0)) }
|
37
38
|
end
|
38
39
|
|
39
40
|
context "by translation" do
|
40
41
|
let(:sort_mode) { :translation }
|
41
42
|
|
42
|
-
it { should
|
43
|
+
it { should eq(%w(3 2 0 1)) }
|
43
44
|
end
|
44
45
|
|
45
46
|
context "by nothing" do
|
46
47
|
let(:sort_mode) { :none }
|
47
48
|
|
48
|
-
it { should
|
49
|
+
it { should eq(%w(1 2 3 0)) }
|
49
50
|
end
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
54
|
it "creates a method that returns the enumeration specification" do
|
54
|
-
TestEnumeration.enumeration.
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
58
|
-
|
55
|
+
expect(TestEnumeration.enumeration).to eq(
|
56
|
+
value_1: ['1', 'Hey, I am 1!'],
|
57
|
+
value_2: ['2', 'Hey, I am 2!'],
|
58
|
+
value_3: ['3', 'Hey, I am 3!']
|
59
|
+
)
|
59
60
|
end
|
60
61
|
|
61
62
|
describe ".length" do
|
62
63
|
it "returns the length of the enumeration" do
|
63
|
-
TestEnumeration.length.
|
64
|
+
expect(TestEnumeration.length).to eq(3)
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
@@ -70,13 +71,13 @@ describe EnumerateIt::Base do
|
|
70
71
|
TestEnumeration.each_translation do |translation|
|
71
72
|
translations << translation
|
72
73
|
end
|
73
|
-
translations.
|
74
|
+
expect(translations).to eq(["Hey, I am 1!", "Hey, I am 2!", "Hey, I am 3!"])
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|
77
78
|
describe ".translations" do
|
78
79
|
it "returns all translations" do
|
79
|
-
TestEnumeration.translations.
|
80
|
+
expect(TestEnumeration.translations).to eq(["Hey, I am 1!", "Hey, I am 2!", "Hey, I am 3!"])
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
@@ -86,115 +87,116 @@ describe EnumerateIt::Base do
|
|
86
87
|
TestEnumeration.each_value do |value|
|
87
88
|
values << value
|
88
89
|
end
|
89
|
-
values.
|
90
|
+
expect(values).to eq(TestEnumeration.list)
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
93
94
|
describe ".to_a" do
|
94
95
|
it "returns an array with the values and human representations" do
|
95
|
-
TestEnumeration.to_a.
|
96
|
+
expect(TestEnumeration.to_a).to eq([['Hey, I am 1!', '1'], ['Hey, I am 2!', '2'], ['Hey, I am 3!', '3']])
|
96
97
|
end
|
97
98
|
|
98
99
|
it "translates the available values" do
|
99
|
-
|
100
|
+
I18n.locale = :en
|
101
|
+
expect(TestEnumerationWithoutArray.to_a).to eq([['First Value', '1'], ['Value Two', '2']])
|
100
102
|
I18n.locale = :pt
|
101
|
-
TestEnumerationWithoutArray.to_a.
|
103
|
+
expect(TestEnumerationWithoutArray.to_a).to eq([['Primeiro Valor', '1'], ['Value Two', '2']])
|
102
104
|
end
|
103
105
|
|
104
106
|
it "can be extended from the enumeration class" do
|
105
|
-
TestEnumerationWithExtendedBehaviour.to_a.
|
107
|
+
expect(TestEnumerationWithExtendedBehaviour.to_a).to eq([['Second', '2'],['First','1']])
|
106
108
|
end
|
107
109
|
end
|
108
110
|
|
109
111
|
describe ".to_json" do
|
110
112
|
it "gives a valid json back" do
|
111
113
|
I18n.locale = :inexsistent
|
112
|
-
TestEnumerationWithoutArray.to_json.
|
114
|
+
expect(TestEnumerationWithoutArray.to_json).to eq('[{"value":"1","label":"Value One"},{"value":"2","label":"Value Two"}]')
|
113
115
|
end
|
114
116
|
|
115
117
|
it "give translated values when available" do
|
116
118
|
I18n.locale = :pt
|
117
|
-
TestEnumerationWithoutArray.to_json.
|
119
|
+
expect(TestEnumerationWithoutArray.to_json).to eq('[{"value":"1","label":"Primeiro Valor"},{"value":"2","label":"Value Two"}]')
|
118
120
|
end
|
119
121
|
end
|
120
122
|
|
121
123
|
describe ".t" do
|
122
124
|
it "translates a given value" do
|
123
125
|
I18n.locale = :pt
|
124
|
-
TestEnumerationWithoutArray.t('1').
|
126
|
+
expect(TestEnumerationWithoutArray.t('1')).to eq('Primeiro Valor')
|
125
127
|
end
|
126
128
|
end
|
127
129
|
|
128
130
|
describe ".to_range" do
|
129
131
|
it "returns a Range object containing the enumeration's value interval" do
|
130
|
-
TestEnumeration.to_range.
|
132
|
+
expect(TestEnumeration.to_range).to eq("1".."3")
|
131
133
|
end
|
132
134
|
end
|
133
135
|
|
134
136
|
describe ".values_for" do
|
135
137
|
it "returns an array with the corresponding values for a string array representing some of the enumeration's values" do
|
136
|
-
TestEnumeration.values_for(%w(VALUE_1 VALUE_2)).
|
138
|
+
expect(TestEnumeration.values_for(%w(VALUE_1 VALUE_2))).to eq([TestEnumeration::VALUE_1, TestEnumeration::VALUE_2])
|
137
139
|
end
|
138
140
|
|
139
141
|
it "returns a nil value if the a constant named after one of the given strings cannot be found" do
|
140
|
-
TestEnumeration.values_for(%w(VALUE_1 THIS_IS_WRONG)).
|
142
|
+
expect(TestEnumeration.values_for(%w(VALUE_1 THIS_IS_WRONG))).to eq([TestEnumeration::VALUE_1, nil])
|
141
143
|
end
|
142
144
|
end
|
143
145
|
|
144
146
|
describe ".value_for" do
|
145
147
|
it "returns the enumeration's value" do
|
146
|
-
TestEnumeration.value_for("VALUE_1").
|
148
|
+
expect(TestEnumeration.value_for("VALUE_1")).to eq(TestEnumeration::VALUE_1)
|
147
149
|
end
|
148
150
|
|
149
151
|
context "when a constant named after the received value cannot be found" do
|
150
152
|
it "returns nil" do
|
151
|
-
TestEnumeration.value_for("THIS_IS_WRONG").
|
153
|
+
expect(TestEnumeration.value_for("THIS_IS_WRONG")).to be_nil
|
152
154
|
end
|
153
155
|
end
|
154
156
|
end
|
155
157
|
|
156
158
|
describe ".value_from_key" do
|
157
159
|
it "returns the correct value when the key is a string" do
|
158
|
-
TestEnumeration.value_from_key("value_1").
|
160
|
+
expect(TestEnumeration.value_from_key("value_1")).to eq(TestEnumeration::VALUE_1)
|
159
161
|
end
|
160
162
|
|
161
163
|
it "returns the correct value when the key is a symbol" do
|
162
|
-
TestEnumeration.value_from_key(:value_1).
|
164
|
+
expect(TestEnumeration.value_from_key(:value_1)).to eq(TestEnumeration::VALUE_1)
|
163
165
|
end
|
164
166
|
|
165
167
|
it "returns nil when the key does not exist in the enumeration" do
|
166
|
-
TestEnumeration.value_from_key("wrong").
|
168
|
+
expect(TestEnumeration.value_from_key("wrong")).to be_nil
|
167
169
|
end
|
168
170
|
|
169
171
|
it "returns nil when the given value is nil" do
|
170
|
-
TestEnumeration.value_from_key(nil).
|
172
|
+
expect(TestEnumeration.value_from_key(nil)).to be_nil
|
171
173
|
end
|
172
174
|
end
|
173
175
|
|
174
176
|
describe ".keys" do
|
175
177
|
it "returns a list with the keys used to define the enumeration" do
|
176
|
-
TestEnumeration.keys.
|
178
|
+
expect(TestEnumeration.keys).to eq([:value_1, :value_2, :value_3])
|
177
179
|
end
|
178
180
|
end
|
179
181
|
|
180
182
|
describe ".key_for" do
|
181
183
|
it "returns the key for the given value inside the enumeration" do
|
182
|
-
TestEnumeration.key_for(TestEnumeration::VALUE_1).
|
184
|
+
expect(TestEnumeration.key_for(TestEnumeration::VALUE_1)).to eq(:value_1)
|
183
185
|
end
|
184
186
|
|
185
187
|
it "returns nil if the enumeration does not have the given value" do
|
186
|
-
TestEnumeration.key_for("foo").
|
188
|
+
expect(TestEnumeration.key_for("foo")).to be_nil
|
187
189
|
end
|
188
190
|
end
|
189
191
|
|
190
192
|
context 'associate values with a list' do
|
191
193
|
it "creates constants for each enumeration value" do
|
192
|
-
TestEnumerationWithList::FIRST.
|
193
|
-
TestEnumerationWithList::SECOND.
|
194
|
+
expect(TestEnumerationWithList::FIRST).to eq("first")
|
195
|
+
expect(TestEnumerationWithList::SECOND).to eq("second")
|
194
196
|
end
|
195
197
|
|
196
198
|
it "returns an array with the values and human representations" do
|
197
|
-
TestEnumerationWithList.to_a.
|
199
|
+
expect(TestEnumerationWithList.to_a).to eq([['First', 'first'], ['Second', 'second']])
|
198
200
|
end
|
199
201
|
end
|
200
202
|
|
@@ -204,30 +206,30 @@ describe EnumerateIt::Base do
|
|
204
206
|
context "by value" do
|
205
207
|
let(:sort_mode) { :value }
|
206
208
|
|
207
|
-
it {
|
209
|
+
it { is_expected.to eq([["jkl", "0"], ["xyz", "1"], ["fgh", "2"], ["abc", "3"]]) }
|
208
210
|
end
|
209
211
|
|
210
212
|
context "by name" do
|
211
213
|
let(:sort_mode) { :name }
|
212
214
|
|
213
|
-
it {
|
215
|
+
it { is_expected.to eq([["fgh", "2"], ["xyz", "1"], ["abc", "3"], ["jkl", "0"]]) }
|
214
216
|
end
|
215
217
|
|
216
218
|
context "by translation" do
|
217
219
|
let(:sort_mode) { :translation }
|
218
220
|
|
219
|
-
it {
|
221
|
+
it { is_expected.to eq([["abc", "3"] ,["fgh", "2"], ["jkl", "0"], ["xyz", "1"]]) }
|
220
222
|
end
|
221
223
|
|
222
224
|
context "by nothing" do
|
223
225
|
let(:sort_mode) { :none }
|
224
226
|
|
225
|
-
it {
|
227
|
+
it { is_expected.to eq([["xyz", "1"], ["fgh", "2"], ["abc", "3"], ["jkl", "0"] ]) }
|
226
228
|
end
|
227
229
|
end
|
228
230
|
|
229
231
|
context "when included in ActiveRecord::Base" do
|
230
|
-
before
|
232
|
+
before do
|
231
233
|
class ActiveRecordStub
|
232
234
|
attr_accessor :bla
|
233
235
|
|
@@ -237,40 +239,56 @@ describe EnumerateIt::Base do
|
|
237
239
|
end
|
238
240
|
end
|
239
241
|
|
240
|
-
ActiveRecordStub.
|
242
|
+
allow(ActiveRecordStub).to receive(:validates_inclusion_of).and_return(true)
|
241
243
|
ActiveRecordStub.extend EnumerateIt
|
242
244
|
end
|
243
245
|
|
244
246
|
it "creates a validation for inclusion" do
|
245
|
-
ActiveRecordStub.
|
247
|
+
expect(ActiveRecordStub).to receive(:validates_inclusion_of).with(:bla, in: TestEnumeration.list, allow_blank: true)
|
246
248
|
class ActiveRecordStub
|
247
|
-
has_enumeration_for :bla, :
|
249
|
+
has_enumeration_for :bla, with: TestEnumeration
|
248
250
|
end
|
249
251
|
end
|
250
252
|
|
251
253
|
context "using the :required option" do
|
252
|
-
before
|
253
|
-
ActiveRecordStub.
|
254
|
+
before do
|
255
|
+
allow(ActiveRecordStub).to receive(:validates_presence_of).and_return(true)
|
254
256
|
end
|
255
257
|
|
256
258
|
it "creates a validation for presence" do
|
257
|
-
ActiveRecordStub.
|
259
|
+
expect(ActiveRecordStub).to receive(:validates_presence_of)
|
258
260
|
class ActiveRecordStub
|
259
|
-
has_enumeration_for :bla, :
|
261
|
+
has_enumeration_for :bla, with: TestEnumeration, required: true
|
260
262
|
end
|
261
263
|
end
|
262
264
|
|
263
265
|
it "passes the given options to the validation method" do
|
264
|
-
ActiveRecordStub.
|
266
|
+
expect(ActiveRecordStub).to receive(:validates_presence_of).with(:bla, if: :some_method)
|
265
267
|
class ActiveRecordStub
|
266
|
-
has_enumeration_for :bla, :
|
268
|
+
has_enumeration_for :bla, with: TestEnumeration, required: { if: :some_method }
|
267
269
|
end
|
268
270
|
end
|
269
271
|
|
270
272
|
it "do not require the attribute by default" do
|
271
|
-
ActiveRecordStub.
|
273
|
+
expect(ActiveRecordStub).to_not receive(:validates_presence_of)
|
274
|
+
class ActiveRecordStub
|
275
|
+
has_enumeration_for :bla, with: TestEnumeration
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
context "using :skip_validation option" do
|
281
|
+
it "doesn't create a validation for inclusion" do
|
282
|
+
expect(ActiveRecordStub).to_not receive(:validates_inclusion_of)
|
283
|
+
class ActiveRecordStub
|
284
|
+
has_enumeration_for :bla, with: TestEnumeration, skip_validation: true
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
it "doesn't create a validation for presence" do
|
289
|
+
expect(ActiveRecordStub).to_not receive(:validates_presence_of)
|
272
290
|
class ActiveRecordStub
|
273
|
-
has_enumeration_for :bla, :
|
291
|
+
has_enumeration_for :bla, with: TestEnumeration, require: true, skip_validation: true
|
274
292
|
end
|
275
293
|
end
|
276
294
|
end
|
data/spec/enumerate_it_spec.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
-
#encoding: utf-8
|
1
|
+
# encoding: utf-8
|
2
|
+
|
2
3
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
4
|
|
4
5
|
describe EnumerateIt do
|
5
|
-
before
|
6
|
+
before do
|
6
7
|
class TestClass
|
7
8
|
extend EnumerateIt
|
8
9
|
attr_accessor :foobar
|
9
|
-
has_enumeration_for :foobar, :
|
10
|
+
has_enumeration_for :foobar, with: TestEnumeration
|
11
|
+
|
12
|
+
def initialize(foobar)
|
13
|
+
@foobar = foobar
|
14
|
+
end
|
10
15
|
|
11
|
-
def initialize(foobar); @foobar = foobar; end
|
12
16
|
I18n.locale = :en
|
13
17
|
end
|
14
18
|
|
@@ -17,33 +21,33 @@ describe EnumerateIt do
|
|
17
21
|
|
18
22
|
context "associating an enumeration with a class attribute" do
|
19
23
|
it "creates an humanized description for the attribute's value" do
|
20
|
-
@target.foobar_humanize.
|
24
|
+
expect(@target.foobar_humanize).to eq('Hey, I am 2!')
|
21
25
|
end
|
22
26
|
|
23
27
|
it "if the attribute is blank, the humanize description is nil" do
|
24
28
|
@target.foobar = nil
|
25
|
-
@target.foobar_humanize.
|
29
|
+
expect(@target.foobar_humanize).to be_nil
|
26
30
|
end
|
27
31
|
|
28
32
|
it "defaults to not creating helper methods" do
|
29
|
-
@target.
|
33
|
+
expect(@target).not_to respond_to(:value_1?)
|
30
34
|
end
|
31
35
|
|
32
36
|
it "stores the enumeration class in a class-level hash" do
|
33
|
-
TestClass.enumerations[:foobar].
|
37
|
+
expect(TestClass.enumerations[:foobar]).to eq(TestEnumeration)
|
34
38
|
end
|
35
39
|
|
36
40
|
context 'use the same enumeration from an inherited class' do
|
37
41
|
before do
|
38
|
-
class
|
42
|
+
class SomeClassWithoutEnum < BaseClass
|
39
43
|
end
|
40
|
-
@target =
|
44
|
+
@target = SomeClassWithoutEnum.new
|
41
45
|
end
|
42
46
|
|
43
47
|
it 'should have use the correct class' do
|
44
48
|
@base = BaseClass.new
|
45
|
-
@base.class.enumerations[:foobar].
|
46
|
-
@target.class.enumerations[:foobar].
|
49
|
+
expect(@base.class.enumerations[:foobar]).to eq(TestEnumeration)
|
50
|
+
expect(@target.class.enumerations[:foobar]).to eq(TestEnumeration)
|
47
51
|
end
|
48
52
|
end
|
49
53
|
|
@@ -56,39 +60,41 @@ describe EnumerateIt do
|
|
56
60
|
end
|
57
61
|
it 'should have use the corret class' do
|
58
62
|
@base = BaseClass.new
|
59
|
-
@base.class.enumerations[:foobar].
|
60
|
-
@target.class.enumerations[:foobar].
|
63
|
+
expect(@base.class.enumerations[:foobar]).to eq(TestEnumeration)
|
64
|
+
expect(@target.class.enumerations[:foobar]).to eq(Foobar)
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
64
68
|
context "passing the value of each option without the human string (just the value, without an array)" do
|
65
|
-
before
|
69
|
+
before do
|
66
70
|
class TestClassForEnumerationWithoutArray
|
67
71
|
extend EnumerateIt
|
68
72
|
attr_accessor :foobar
|
69
|
-
has_enumeration_for :foobar, :
|
73
|
+
has_enumeration_for :foobar, with: TestEnumerationWithoutArray
|
70
74
|
|
71
|
-
def initialize(foobar)
|
75
|
+
def initialize(foobar)
|
76
|
+
@foobar = foobar
|
77
|
+
end
|
72
78
|
end
|
73
79
|
|
74
80
|
@target = TestClassForEnumerationWithoutArray.new(TestEnumerationWithoutArray::VALUE_TWO)
|
75
81
|
end
|
76
82
|
|
77
83
|
it "humanizes the respective hash key" do
|
78
|
-
@target.foobar_humanize.
|
84
|
+
expect(@target.foobar_humanize).to eq('Value Two')
|
79
85
|
end
|
80
86
|
|
81
87
|
it "translates the respective hash key when a translation is found" do
|
82
88
|
@target.foobar = TestEnumerationWithoutArray::VALUE_ONE
|
83
|
-
@target.foobar_humanize.
|
89
|
+
expect(@target.foobar_humanize).to eq('First Value')
|
84
90
|
I18n.locale = :pt
|
85
91
|
|
86
|
-
@target.foobar_humanize.
|
92
|
+
expect(@target.foobar_humanize).to eq('Primeiro Valor')
|
87
93
|
end
|
88
94
|
end
|
89
95
|
|
90
96
|
context "without passing the enumeration class" do
|
91
|
-
before
|
97
|
+
before do
|
92
98
|
class FooBar
|
93
99
|
extend EnumerateIt
|
94
100
|
attr_accessor :test_enumeration
|
@@ -103,18 +109,18 @@ describe EnumerateIt do
|
|
103
109
|
|
104
110
|
it "should find out which enumeration class to use" do
|
105
111
|
target = FooBar.new(TestEnumeration::VALUE_1)
|
106
|
-
target.test_enumeration_humanize.
|
112
|
+
expect(target.test_enumeration_humanize).to eq('Hey, I am 1!')
|
107
113
|
end
|
108
114
|
|
109
115
|
context "when using a nested class as the enumeration" do
|
110
116
|
before do
|
111
117
|
class NestedEnum < EnumerateIt::Base
|
112
|
-
associate_values :
|
118
|
+
associate_values foo: ['1', 'Fooo'], bar: ['2', 'Barrrr']
|
113
119
|
end
|
114
120
|
|
115
121
|
class ClassWithNestedEnum
|
116
122
|
class NestedEnum < EnumerateIt::Base
|
117
|
-
associate_values :
|
123
|
+
associate_values foo: ['1', 'Blerrgh'], bar: ['2' => 'Blarghhh']
|
118
124
|
end
|
119
125
|
|
120
126
|
extend EnumerateIt
|
@@ -130,68 +136,74 @@ describe EnumerateIt do
|
|
130
136
|
end
|
131
137
|
|
132
138
|
it "uses the inner class as the enumeration class" do
|
133
|
-
|
139
|
+
expect(ClassWithNestedEnum.new('1').nested_enum_humanize).to eq('Blerrgh')
|
134
140
|
end
|
135
141
|
end
|
136
142
|
end
|
137
143
|
end
|
138
144
|
|
139
145
|
context "using the :create_helpers option" do
|
140
|
-
before
|
141
|
-
class
|
142
|
-
|
146
|
+
before do
|
147
|
+
class TestClassWithHelper
|
148
|
+
extend EnumerateIt
|
149
|
+
attr_accessor :foobar
|
150
|
+
has_enumeration_for :foobar, with: TestEnumeration, create_helpers: true
|
151
|
+
|
152
|
+
def initialize(foobar)
|
153
|
+
@foobar = foobar
|
154
|
+
end
|
143
155
|
end
|
144
156
|
end
|
145
157
|
|
146
158
|
it "creates helpers methods with question marks for each enumeration option" do
|
147
|
-
target =
|
148
|
-
target.
|
149
|
-
target.
|
159
|
+
target = TestClassWithHelper.new(TestEnumeration::VALUE_2)
|
160
|
+
expect(target).to be_value_2
|
161
|
+
expect(target).not_to be_value_1
|
150
162
|
end
|
151
163
|
|
152
164
|
it "creates a mutator method for each enumeration value" do
|
153
165
|
[:value_1, :value_2, :value_3].each do |value|
|
154
|
-
|
166
|
+
expect(TestClassWithHelper.new(TestEnumeration::VALUE_1)).to respond_to(:"#{value}!")
|
155
167
|
end
|
156
168
|
end
|
157
169
|
|
158
170
|
it "changes the attribute's value through mutator methods" do
|
159
|
-
target =
|
171
|
+
target = TestClassWithHelper.new(TestEnumeration::VALUE_2)
|
160
172
|
target.value_3!
|
161
|
-
target.foobar.
|
173
|
+
expect(target.foobar).to eq(TestEnumeration::VALUE_3)
|
162
174
|
end
|
163
175
|
|
164
176
|
context "with :prefix option" do
|
165
|
-
before
|
166
|
-
class
|
167
|
-
has_enumeration_for :foobar, :
|
177
|
+
before do
|
178
|
+
class TestClassWithHelper
|
179
|
+
has_enumeration_for :foobar, with: TestEnumeration, create_helpers: { prefix: true }
|
168
180
|
end
|
169
181
|
end
|
170
182
|
|
171
183
|
it "creates helpers methods with question marks and prefixes for each enumeration option" do
|
172
|
-
target =
|
173
|
-
target.
|
184
|
+
target = TestClassWithHelper.new(TestEnumeration::VALUE_2)
|
185
|
+
expect(target).to be_foobar_value_2
|
174
186
|
end
|
175
187
|
|
176
188
|
it "creates a mutator method for each enumeration value" do
|
177
189
|
[:value_1, :value_2, :value_3].each do |value|
|
178
|
-
|
190
|
+
expect(TestClassWithHelper.new(TestEnumeration::VALUE_1)).to respond_to(:"foobar_#{value}!")
|
179
191
|
end
|
180
192
|
end
|
181
193
|
|
182
194
|
it "changes the attribute's value through mutator methods" do
|
183
|
-
target =
|
195
|
+
target = TestClassWithHelper.new(TestEnumeration::VALUE_2)
|
184
196
|
target.foobar_value_3!
|
185
|
-
target.foobar.
|
197
|
+
expect(target.foobar).to eq(TestEnumeration::VALUE_3)
|
186
198
|
end
|
187
199
|
end
|
188
200
|
|
189
201
|
context "with :polymorphic option" do
|
190
|
-
before
|
202
|
+
before do
|
191
203
|
class Polymorphic
|
192
204
|
extend EnumerateIt
|
193
205
|
attr_accessor :foo
|
194
|
-
has_enumeration_for :foo, :
|
206
|
+
has_enumeration_for :foo, with: PolymorphicEnum, create_helpers: { polymorphic: true }
|
195
207
|
end
|
196
208
|
end
|
197
209
|
|
@@ -199,23 +211,23 @@ describe EnumerateIt do
|
|
199
211
|
target = Polymorphic.new
|
200
212
|
target.foo = PolymorphicEnum::NORMAL
|
201
213
|
|
202
|
-
target.foo_object.print("Gol").
|
214
|
+
expect(target.foo_object.print("Gol")).to eq("I'm Normal: Gol")
|
203
215
|
|
204
216
|
target.foo = PolymorphicEnum::CRAZY
|
205
217
|
|
206
|
-
target.foo_object.print("Gol").
|
218
|
+
expect(target.foo_object.print("Gol")).to eq("Whoa!: Gol")
|
207
219
|
end
|
208
220
|
|
209
221
|
it "returns nil if foo is not set" do
|
210
222
|
target = Polymorphic.new
|
211
223
|
|
212
|
-
target.foo_object.
|
224
|
+
expect(target.foo_object).to be_nil
|
213
225
|
end
|
214
226
|
|
215
227
|
context "and :suffix" do
|
216
|
-
before
|
228
|
+
before do
|
217
229
|
class Polymorphic
|
218
|
-
has_enumeration_for :foo, :
|
230
|
+
has_enumeration_for :foo, with: PolymorphicEnum, create_helpers: { polymorphic: { suffix: "_strategy" } }
|
219
231
|
end
|
220
232
|
end
|
221
233
|
|
@@ -223,44 +235,39 @@ describe EnumerateIt do
|
|
223
235
|
target = Polymorphic.new
|
224
236
|
target.foo = PolymorphicEnum::NORMAL
|
225
237
|
|
226
|
-
target.foo_strategy.print("Gol").
|
238
|
+
expect(target.foo_strategy.print("Gol")).to eq("I'm Normal: Gol")
|
227
239
|
|
228
240
|
target.foo = PolymorphicEnum::CRAZY
|
229
241
|
|
230
|
-
target.foo_strategy.print("Gol").
|
242
|
+
expect(target.foo_strategy.print("Gol")).to eq("Whoa!: Gol")
|
231
243
|
end
|
232
244
|
end
|
233
245
|
end
|
234
246
|
end
|
235
247
|
|
236
248
|
describe "using the :create_scopes option" do
|
237
|
-
def setup_enumeration
|
238
|
-
OtherTestClass.send(:has_enumeration_for, :foobar, :with => TestEnumeration, :create_scopes => true)
|
239
|
-
end
|
240
|
-
|
241
249
|
context "if the hosting class responds to :scope" do
|
242
250
|
before do
|
243
251
|
if ActiveSupport::VERSION::STRING =~ /3\.1/
|
244
|
-
Object.send :remove_const, '
|
252
|
+
Object.send :remove_const, 'TestClassWithScope' if defined?(TestClassWithScope)
|
245
253
|
end
|
246
254
|
|
247
|
-
class
|
255
|
+
class TestClassWithScope < ActiveRecord::Base
|
248
256
|
extend EnumerateIt
|
257
|
+
has_enumeration_for :foobar, with: TestEnumeration, create_scopes: true
|
249
258
|
end
|
250
|
-
|
251
|
-
setup_enumeration
|
252
259
|
end
|
253
260
|
|
254
261
|
it "creates a scope for each enumeration value" do
|
255
262
|
TestEnumeration.enumeration.keys.each do |symbol|
|
256
|
-
|
263
|
+
expect(TestClassWithScope).to respond_to(symbol)
|
257
264
|
end
|
258
265
|
end
|
259
266
|
|
260
267
|
it "when called, the scopes create the correct query" do
|
261
268
|
TestEnumeration.enumeration.each do |symbol, pair|
|
262
|
-
|
263
|
-
|
269
|
+
expect(TestClassWithScope).to receive(:where).with(foobar: pair.first)
|
270
|
+
TestClassWithScope.send symbol
|
264
271
|
end
|
265
272
|
end
|
266
273
|
end
|
@@ -274,22 +281,22 @@ describe EnumerateIt do
|
|
274
281
|
|
275
282
|
it "raises no errors" do
|
276
283
|
expect {
|
277
|
-
GenericClass.send(:has_enumeration_for, :foobar, :
|
284
|
+
GenericClass.send(:has_enumeration_for, :foobar, with: TestEnumeration, create_scopes: true)
|
278
285
|
}.to_not raise_error
|
279
286
|
end
|
280
287
|
end
|
281
288
|
|
282
289
|
context "with :prefix option" do
|
283
290
|
before do
|
284
|
-
class OtherTestClass
|
291
|
+
class OtherTestClass < ActiveRecord::Base
|
285
292
|
extend EnumerateIt
|
286
|
-
has_enumeration_for :foobar, :
|
293
|
+
has_enumeration_for :foobar, with: TestEnumerationWithReservedWords, create_scopes: { prefix: true }
|
287
294
|
end
|
288
295
|
end
|
289
296
|
|
290
297
|
it "creates a scope with prefix for each enumeration value" do
|
291
298
|
TestEnumerationWithReservedWords.enumeration.keys.each do |symbol|
|
292
|
-
OtherTestClass.
|
299
|
+
expect(OtherTestClass).to respond_to(:"foobar_#{symbol}")
|
293
300
|
end
|
294
301
|
end
|
295
302
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,6 +10,7 @@ Dir['./spec/support/**/*.rb'].each { |f| require f }
|
|
10
10
|
I18n.config.enforce_available_locales = false
|
11
11
|
I18n.load_path = Dir['spec/i18n/*.yml']
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.filter_run_including focus: true
|
15
|
+
config.run_all_when_everything_filtered = true
|
16
|
+
end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
class TestEnumeration < EnumerateIt::Base
|
2
2
|
associate_values(
|
3
|
-
:
|
4
|
-
:
|
5
|
-
:
|
3
|
+
value_1: ['1', 'Hey, I am 1!'],
|
4
|
+
value_2: ['2', 'Hey, I am 2!'],
|
5
|
+
value_3: ['3', 'Hey, I am 3!']
|
6
6
|
)
|
7
7
|
end
|
8
8
|
|
9
9
|
class TestEnumerationWithoutArray < EnumerateIt::Base
|
10
10
|
associate_values(
|
11
|
-
:
|
12
|
-
:
|
11
|
+
value_one: '1',
|
12
|
+
value_two: '2'
|
13
13
|
)
|
14
14
|
end
|
15
15
|
|
16
16
|
class TestEnumerationWithExtendedBehaviour < EnumerateIt::Base
|
17
17
|
associate_values(
|
18
|
-
:
|
19
|
-
:
|
18
|
+
first: '1',
|
19
|
+
second: '2'
|
20
20
|
)
|
21
21
|
def self.to_a
|
22
22
|
super.reverse
|
@@ -28,7 +28,7 @@ class TestEnumerationWithList < EnumerateIt::Base
|
|
28
28
|
end
|
29
29
|
|
30
30
|
class TestEnumerationWithReservedWords < EnumerateIt::Base
|
31
|
-
associate_values :
|
31
|
+
associate_values new: 1, no_schedule: 2, with_schedule: 3, suspended: 4
|
32
32
|
end
|
33
33
|
|
34
34
|
class TestEnumerationWithDash < EnumerateIt::Base
|
@@ -45,7 +45,7 @@ end
|
|
45
45
|
|
46
46
|
class Foobar < EnumerateIt::Base
|
47
47
|
associate_values(
|
48
|
-
:
|
48
|
+
bar: 'foo'
|
49
49
|
)
|
50
50
|
end
|
51
51
|
|
@@ -67,7 +67,7 @@ end
|
|
67
67
|
|
68
68
|
class BaseClass
|
69
69
|
extend EnumerateIt
|
70
|
-
has_enumeration_for :foobar, :
|
70
|
+
has_enumeration_for :foobar, with: TestEnumeration
|
71
71
|
end
|
72
72
|
|
73
73
|
def create_enumeration_class_with_sort_mode(sort_mode)
|
@@ -75,11 +75,10 @@ def create_enumeration_class_with_sort_mode(sort_mode)
|
|
75
75
|
sort_by sort_mode
|
76
76
|
|
77
77
|
associate_values(
|
78
|
-
:
|
79
|
-
:
|
80
|
-
:
|
81
|
-
:
|
78
|
+
foo: ["1", "xyz"],
|
79
|
+
bar: ["2", "fgh"],
|
80
|
+
omg: ["3", "abc"],
|
81
|
+
zomg: ["0", "jkl"]
|
82
82
|
)
|
83
83
|
end
|
84
84
|
end
|
85
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumerate_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cássio Marques
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -71,16 +71,30 @@ dependencies:
|
|
71
71
|
name: rspec
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - "
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
76
|
+
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - "
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rubocop
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
82
89
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
84
98
|
description: Enumerations for Ruby with some magic powers!
|
85
99
|
email:
|
86
100
|
executables: []
|
@@ -90,6 +104,7 @@ files:
|
|
90
104
|
- ".document"
|
91
105
|
- ".gitignore"
|
92
106
|
- ".rspec"
|
107
|
+
- ".ruby-version"
|
93
108
|
- ".travis.yml"
|
94
109
|
- Appraisals
|
95
110
|
- CHANGELOG.md
|