enumerate_it 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -7
- data/.travis.yml +6 -1
- data/Appraisals +1 -1
- data/Gemfile.lock +22 -20
- data/README.md +27 -27
- data/Rakefile +0 -2
- data/gemfiles/rails_4.2.gemfile +2 -2
- data/gemfiles/rails_5.0.gemfile +2 -2
- data/gemfiles/rails_5.1.gemfile +8 -0
- data/lib/enumerate_it.rb +2 -2
- data/lib/enumerate_it/base.rb +0 -2
- data/lib/enumerate_it/class_methods.rb +0 -2
- data/lib/enumerate_it/version.rb +1 -1
- data/spec/enumerate_it/base_spec.rb +0 -2
- data/spec/enumerate_it_spec.rb +0 -4
- metadata +4 -6
- data/lib/generators/enumerate_it/install/USAGE +0 -8
- data/lib/generators/enumerate_it/install/install_generator.rb +0 -11
- data/lib/generators/enumerate_it/install/templates/enumerate_it_initializer.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1558c3ef8bfaf0bfe9ec496af98f6fd794b04dde
|
4
|
+
data.tar.gz: bf56fe8d302929046e3acb21d246fe3a25745bdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a39df4cbd269760cbbd1b0d7dc0176c49253f781fa587202307dacc56d3c020c6e37e02b447ec179fb64857df39f9d75d31cb6642d395ab34a6ef5eb1ad03b49
|
7
|
+
data.tar.gz: 43d0aab4b4753bdd6af81131f57b4e1ca766f3ee48182c20ff8513b5c4c6d24a051787420ec499e9eddadbda66cb6e5ffa052c0036695d07cc7b074af00efd2e
|
data/.rubocop.yml
CHANGED
@@ -21,24 +21,24 @@ Metrics/BlockLength:
|
|
21
21
|
Exclude:
|
22
22
|
- 'spec/**/*'
|
23
23
|
|
24
|
-
|
24
|
+
Layout/AlignHash:
|
25
25
|
EnforcedLastArgumentHashStyle: ignore_implicit
|
26
26
|
|
27
|
-
|
27
|
+
Layout/ElseAlignment:
|
28
28
|
Enabled: false
|
29
29
|
|
30
|
-
|
30
|
+
Layout/IndentationWidth:
|
31
31
|
Enabled: false
|
32
32
|
|
33
|
+
Layout/MultilineMethodCallIndentation:
|
34
|
+
EnforcedStyle: indented
|
35
|
+
|
33
36
|
Style/FrozenStringLiteralComment:
|
34
37
|
Enabled: false
|
35
38
|
|
36
|
-
Style/
|
39
|
+
Style/Documentation:
|
37
40
|
Enabled: false
|
38
41
|
|
39
|
-
Style/MultilineMethodCallIndentation:
|
40
|
-
EnforcedStyle: indented
|
41
|
-
|
42
42
|
Style/PredicateName:
|
43
43
|
Exclude:
|
44
44
|
- 'lib/enumerate_it/class_methods.rb'
|
data/.travis.yml
CHANGED
@@ -23,14 +23,19 @@ gemfile:
|
|
23
23
|
- gemfiles/rails_4.1.gemfile
|
24
24
|
- gemfiles/rails_4.2.gemfile
|
25
25
|
- gemfiles/rails_5.0.gemfile
|
26
|
+
- gemfiles/rails_5.1.gemfile
|
26
27
|
|
27
28
|
matrix:
|
28
29
|
exclude:
|
29
|
-
# Rails 5 requires Ruby
|
30
|
+
# Rails 5+ requires Ruby 2.2+
|
30
31
|
- rvm: 2.0.0
|
31
32
|
gemfile: gemfiles/rails_5.0.gemfile
|
33
|
+
- rvm: 2.0.0
|
34
|
+
gemfile: gemfiles/rails_5.1.gemfile
|
32
35
|
- rvm: 2.1.10
|
33
36
|
gemfile: gemfiles/rails_5.0.gemfile
|
37
|
+
- rvm: 2.1.10
|
38
|
+
gemfile: gemfiles/rails_5.1.gemfile
|
34
39
|
|
35
40
|
# Rails 4.0 and 4.1 requires an old version of `json` gem, which isn't compatible with Ruby 2.4+
|
36
41
|
# https://github.com/flori/json/issues/308
|
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[3.0 3.1 3.2 4.0 4.1 4.2 5.0].each do |version|
|
7
|
+
%w[3.0 3.1 3.2 4.0 4.1 4.2 5.0 5.1].each do |version|
|
8
8
|
appraise "rails_#{version}" do
|
9
9
|
current_version = rails_versions.select { |key| key.match(/\A#{version}/) }.max
|
10
10
|
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
enumerate_it (1.
|
4
|
+
enumerate_it (1.6.0)
|
5
5
|
activesupport (>= 3.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (5.
|
10
|
+
activesupport (5.1.3)
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
12
|
i18n (~> 0.7)
|
13
13
|
minitest (~> 5.1)
|
@@ -20,9 +20,10 @@ GEM
|
|
20
20
|
coderay (1.1.1)
|
21
21
|
concurrent-ruby (1.0.5)
|
22
22
|
diff-lcs (1.3)
|
23
|
-
i18n (0.8.
|
23
|
+
i18n (0.8.6)
|
24
24
|
method_source (0.8.2)
|
25
|
-
minitest (5.10.
|
25
|
+
minitest (5.10.3)
|
26
|
+
parallel (1.12.0)
|
26
27
|
parser (2.4.0.0)
|
27
28
|
ast (~> 2.2)
|
28
29
|
powerpack (0.1.1)
|
@@ -33,34 +34,35 @@ GEM
|
|
33
34
|
rainbow (2.2.2)
|
34
35
|
rake
|
35
36
|
rake (12.0.0)
|
36
|
-
rspec (3.
|
37
|
-
rspec-core (~> 3.
|
38
|
-
rspec-expectations (~> 3.
|
39
|
-
rspec-mocks (~> 3.
|
40
|
-
rspec-core (3.
|
41
|
-
rspec-support (~> 3.
|
42
|
-
rspec-expectations (3.
|
37
|
+
rspec (3.6.0)
|
38
|
+
rspec-core (~> 3.6.0)
|
39
|
+
rspec-expectations (~> 3.6.0)
|
40
|
+
rspec-mocks (~> 3.6.0)
|
41
|
+
rspec-core (3.6.0)
|
42
|
+
rspec-support (~> 3.6.0)
|
43
|
+
rspec-expectations (3.6.0)
|
43
44
|
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
-
rspec-support (~> 3.
|
45
|
-
rspec-mocks (3.
|
45
|
+
rspec-support (~> 3.6.0)
|
46
|
+
rspec-mocks (3.6.0)
|
46
47
|
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
-
rspec-support (~> 3.
|
48
|
-
rspec-support (3.
|
49
|
-
rubocop (0.
|
48
|
+
rspec-support (~> 3.6.0)
|
49
|
+
rspec-support (3.6.0)
|
50
|
+
rubocop (0.49.1)
|
51
|
+
parallel (~> 1.10)
|
50
52
|
parser (>= 2.3.3.1, < 3.0)
|
51
53
|
powerpack (~> 0.1)
|
52
54
|
rainbow (>= 1.99.1, < 3.0)
|
53
55
|
ruby-progressbar (~> 1.7)
|
54
56
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
55
|
-
rubocop-rspec (1.15.
|
57
|
+
rubocop-rspec (1.15.1)
|
56
58
|
rubocop (>= 0.42.0)
|
57
59
|
ruby-progressbar (1.8.1)
|
58
60
|
slop (3.6.0)
|
59
|
-
thor (0.
|
61
|
+
thor (0.20.0)
|
60
62
|
thread_safe (0.3.6)
|
61
63
|
tzinfo (1.2.3)
|
62
64
|
thread_safe (~> 0.1)
|
63
|
-
unicode-display_width (1.
|
65
|
+
unicode-display_width (1.3.0)
|
64
66
|
wwtd (1.3.0)
|
65
67
|
|
66
68
|
PLATFORMS
|
@@ -78,4 +80,4 @@ DEPENDENCIES
|
|
78
80
|
wwtd
|
79
81
|
|
80
82
|
BUNDLED WITH
|
81
|
-
1.
|
83
|
+
1.15.4
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# EnumerateIt
|
2
2
|
|
3
|
-
|
3
|
+
Ruby Enumerations with magic powers! 🎩
|
4
4
|
|
5
5
|
[![Build Status](https://travis-ci.org/lucascaton/enumerate_it.svg?branch=master)](https://travis-ci.org/lucascaton/enumerate_it)
|
6
6
|
[![Gem Version](https://badge.fury.io/rb/enumerate_it.svg)](https://rubygems.org/gems/enumerate_it)
|
@@ -47,13 +47,7 @@ Add the gem to your Gemfile:
|
|
47
47
|
gem 'enumerate_it'
|
48
48
|
```
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
```bash
|
53
|
-
rails generate enumerate_it:install
|
54
|
-
```
|
55
|
-
|
56
|
-
There is also a Rails Generator which generates enumerations and their locale files:
|
50
|
+
You can use a Rails generator, which generates enumerations and their locale files:
|
57
51
|
|
58
52
|
```bash
|
59
53
|
rails generate enumerate_it:enum --help
|
@@ -183,10 +177,17 @@ The `sort_by` method accepts one of the following values:
|
|
183
177
|
|
184
178
|
## Using enumerations
|
185
179
|
|
186
|
-
The cool part is that you can use these enumerations with any class
|
187
|
-
|
180
|
+
The cool part is that you can use these enumerations with any class:
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
# ActiveRecord instance
|
184
|
+
class Person < ApplicationRecord
|
185
|
+
has_enumeration_for :relationship_status
|
186
|
+
end
|
187
|
+
```
|
188
188
|
|
189
189
|
```ruby
|
190
|
+
# Non-ActiveRecord instance
|
190
191
|
class Person
|
191
192
|
extend EnumerateIt
|
192
193
|
attr_accessor :relationship_status
|
@@ -231,7 +232,7 @@ This will create:
|
|
231
232
|
* A helper method for each enumeration option, if you pass the `create_helpers` option as `true`:
|
232
233
|
|
233
234
|
```ruby
|
234
|
-
class Person <
|
235
|
+
class Person < ApplicationRecord
|
235
236
|
has_enumeration_for :relationship_status, with: RelationshipStatus, create_helpers: true
|
236
237
|
end
|
237
238
|
|
@@ -249,7 +250,7 @@ This will create:
|
|
249
250
|
option. This can be useful when two or more of the enumerations used share the same constants:
|
250
251
|
|
251
252
|
```ruby
|
252
|
-
class Person <
|
253
|
+
class Person < ApplicationRecord
|
253
254
|
has_enumeration_for :relationship_status,
|
254
255
|
with: RelationshipStatus, create_helpers: { prefix: true }
|
255
256
|
end
|
@@ -279,12 +280,12 @@ This will create:
|
|
279
280
|
|
280
281
|
class Single
|
281
282
|
def saturday_night
|
282
|
-
'Party
|
283
|
+
'Party hard!'
|
283
284
|
end
|
284
285
|
end
|
285
286
|
end
|
286
287
|
|
287
|
-
class Person <
|
288
|
+
class Person < ApplicationRecord
|
288
289
|
has_enumeration_for :relationship_status,
|
289
290
|
with: RelationshipStatus, create_helpers: { polymorphic: true }
|
290
291
|
end
|
@@ -296,13 +297,13 @@ This will create:
|
|
296
297
|
|
297
298
|
p.relationship_status = RelationshipStatus::SINGLE
|
298
299
|
p.relationship_status_object.saturday_night
|
299
|
-
#=> 'Party
|
300
|
+
#=> 'Party hard!'
|
300
301
|
```
|
301
302
|
|
302
303
|
You can also change the suffix `_object`, using the `suffix` option:
|
303
304
|
|
304
305
|
```ruby
|
305
|
-
class Person <
|
306
|
+
class Person < ApplicationRecord
|
306
307
|
has_enumeration_for :relationship_status,
|
307
308
|
with: RelationshipStatus, create_helpers: { polymorphic: { suffix: '_mode' } }
|
308
309
|
end
|
@@ -324,7 +325,7 @@ This will create:
|
|
324
325
|
* A scope method for each enumeration option if you pass the `create_scopes` option as `true`:
|
325
326
|
|
326
327
|
```ruby
|
327
|
-
class Person <
|
328
|
+
class Person < ApplicationRecord
|
328
329
|
has_enumeration_for :relationship_status, with: RelationshipStatus, create_scopes: true
|
329
330
|
end
|
330
331
|
|
@@ -335,7 +336,7 @@ This will create:
|
|
335
336
|
The `:create_scopes` also accepts `prefix` option.
|
336
337
|
|
337
338
|
```ruby
|
338
|
-
class Person <
|
339
|
+
class Person < ApplicationRecord
|
339
340
|
has_enumeration_for :relationship_status,
|
340
341
|
with: RelationshipStatus, create_scopes: { prefix: true }
|
341
342
|
end
|
@@ -347,7 +348,7 @@ This will create:
|
|
347
348
|
`validates_inclusion_of`):
|
348
349
|
|
349
350
|
```ruby
|
350
|
-
class Person <
|
351
|
+
class Person < ApplicationRecord
|
351
352
|
has_enumeration_for :relationship_status, with: RelationshipStatus
|
352
353
|
end
|
353
354
|
|
@@ -358,11 +359,11 @@ This will create:
|
|
358
359
|
#=> 'is not included in the list'
|
359
360
|
```
|
360
361
|
|
361
|
-
*
|
362
|
+
* A presence validation (if your class can manage validations and responds to
|
362
363
|
`validates_presence_of` and you pass the `required` options as `true`):
|
363
364
|
|
364
365
|
```ruby
|
365
|
-
class Person <
|
366
|
+
class Person < ApplicationRecord
|
366
367
|
has_enumeration_for :relationship_status, required: true
|
367
368
|
end
|
368
369
|
|
@@ -376,7 +377,7 @@ This will create:
|
|
376
377
|
If you pass the `skip_validation` option as `true`, it will not create any validations:
|
377
378
|
|
378
379
|
```ruby
|
379
|
-
class Person <
|
380
|
+
class Person < ApplicationRecord
|
380
381
|
has_enumeration_for :relationship_status, with: RelationshipStatus, skip_validation: true
|
381
382
|
end
|
382
383
|
|
@@ -385,8 +386,7 @@ This will create:
|
|
385
386
|
#=> true
|
386
387
|
```
|
387
388
|
|
388
|
-
Remember that you can add validations to any kind of class and not only
|
389
|
-
`ActiveRecord::Base`.
|
389
|
+
Remember that you can add validations to any kind of class and not only `ActiveRecord` ones.
|
390
390
|
|
391
391
|
## FAQ
|
392
392
|
|
@@ -402,8 +402,8 @@ You sure can! 😄
|
|
402
402
|
|
403
403
|
#### What versions of Ruby and Rails are supported?
|
404
404
|
|
405
|
-
* **Ruby** `2.0`
|
406
|
-
* **Rails** `3.0`
|
405
|
+
* **Ruby** `2.0` - `2.4`
|
406
|
+
* **Rails** `3.0` - `5.1`
|
407
407
|
|
408
408
|
All versions are tested via
|
409
409
|
[Travis](https://github.com/lucascaton/enumerate_it/blob/master/.travis.yml).
|
@@ -514,7 +514,7 @@ Changes are maintained under [Releases](https://github.com/lucascaton/enumerate_
|
|
514
514
|
* Fork the project.
|
515
515
|
* Make your feature addition or bug fix.
|
516
516
|
* Add tests for it. This is important so we don't break it in a future version unintentionally.
|
517
|
-
* [Optional] Run the tests agaist a specific Gemfile: `$ bundle exec appraisal rails_5.
|
517
|
+
* [Optional] Run the tests agaist a specific Gemfile: `$ bundle exec appraisal rails_5.1 rake spec`.
|
518
518
|
* Run the tests agaist all supported versions: `$ bundle exec rake` (or `$ bundle exec wwtd`)
|
519
519
|
* Commit, but please do not mess with `Rakefile`, version, or history.
|
520
520
|
* Send a Pull Request. Bonus points for topic branches.
|
data/Rakefile
CHANGED
data/gemfiles/rails_4.2.gemfile
CHANGED
data/gemfiles/rails_5.0.gemfile
CHANGED
data/lib/enumerate_it.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'active_support/core_ext/class/attribute'
|
4
2
|
require 'active_support/inflector'
|
5
3
|
require 'enumerate_it/base'
|
@@ -13,3 +11,5 @@ module EnumerateIt
|
|
13
11
|
receiver.extend ClassMethods
|
14
12
|
end
|
15
13
|
end
|
14
|
+
|
15
|
+
ActiveSupport.on_load(:active_record) { ActiveRecord::Base.extend EnumerateIt }
|
data/lib/enumerate_it/base.rb
CHANGED
data/lib/enumerate_it/version.rb
CHANGED
data/spec/enumerate_it_spec.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
4
2
|
|
5
3
|
describe EnumerateIt do
|
@@ -256,7 +254,6 @@ describe EnumerateIt do
|
|
256
254
|
Object.send :remove_const, 'TestClassWithScope' if defined?(TestClassWithScope)
|
257
255
|
|
258
256
|
class TestClassWithScope < ActiveRecord::Base
|
259
|
-
extend EnumerateIt
|
260
257
|
has_enumeration_for :foobar, with: TestEnumeration, create_scopes: true
|
261
258
|
end
|
262
259
|
end
|
@@ -292,7 +289,6 @@ describe EnumerateIt do
|
|
292
289
|
context 'with :prefix option' do
|
293
290
|
before do
|
294
291
|
class OtherTestClass < ActiveRecord::Base
|
295
|
-
extend EnumerateIt
|
296
292
|
has_enumeration_for :foobar, with: TestEnumerationWithReservedWords,
|
297
293
|
create_scopes: { prefix: true }
|
298
294
|
end
|
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.6.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: 2017-
|
12
|
+
date: 2017-08-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- gemfiles/rails_4.1.gemfile
|
164
164
|
- gemfiles/rails_4.2.gemfile
|
165
165
|
- gemfiles/rails_5.0.gemfile
|
166
|
+
- gemfiles/rails_5.1.gemfile
|
166
167
|
- lib/enumerate_it.rb
|
167
168
|
- lib/enumerate_it/base.rb
|
168
169
|
- lib/enumerate_it/class_methods.rb
|
@@ -171,9 +172,6 @@ files:
|
|
171
172
|
- lib/generators/enumerate_it/enum/enum_generator.rb
|
172
173
|
- lib/generators/enumerate_it/enum/templates/enumerate_it.rb
|
173
174
|
- lib/generators/enumerate_it/enum/templates/locale.yml
|
174
|
-
- lib/generators/enumerate_it/install/USAGE
|
175
|
-
- lib/generators/enumerate_it/install/install_generator.rb
|
176
|
-
- lib/generators/enumerate_it/install/templates/enumerate_it_initializer.rb
|
177
175
|
- spec/enumerate_it/base_spec.rb
|
178
176
|
- spec/enumerate_it_spec.rb
|
179
177
|
- spec/i18n/en.yml
|
@@ -199,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
197
|
version: '0'
|
200
198
|
requirements: []
|
201
199
|
rubyforge_project:
|
202
|
-
rubygems_version: 2.6.
|
200
|
+
rubygems_version: 2.6.12
|
203
201
|
signing_key:
|
204
202
|
specification_version: 4
|
205
203
|
summary: Ruby Enumerations
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module EnumerateIt
|
2
|
-
module Generators
|
3
|
-
class InstallGenerator < Rails::Generators::Base
|
4
|
-
source_root File.expand_path('../templates', __FILE__)
|
5
|
-
|
6
|
-
def copy_initializer_file
|
7
|
-
template 'enumerate_it_initializer.rb', File.join('config/initializers/', 'enumerate_it.rb')
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
ActiveRecord::Base.extend EnumerateIt
|