enumify 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/Appraisals +31 -5
- data/Gemfile +1 -2
- data/Readme.md +16 -0
- data/gemfiles/rails30.gemfile +9 -1
- data/gemfiles/rails31.gemfile +9 -1
- data/gemfiles/rails32.gemfile +9 -1
- data/gemfiles/rails40.gemfile +7 -1
- data/gemfiles/rails41.gemfile +7 -1
- data/lib/enumify/model.rb +6 -1
- data/lib/enumify/version.rb +1 -1
- data/spec/enumify/enum_spec.rb +48 -2
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 635791d1c61f10feee7cebf75a2be9a06ff95a20
|
4
|
+
data.tar.gz: 37859ccd1e25feb2789a52a151cf4fb5194e9596
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9061022d1e98c0c006b3969041d48e6af15bf5df51ffa516c4d2c75e2e755945a70ae4e4d8b1838288f50f52efe9669f83d6958ecf76679e524e35a7e152b4e
|
7
|
+
data.tar.gz: 2ab5669fade3bdebd803c55838a0dee632b70632d15f324aa239ee5003cfd8e01e2f71478ca0739969087ed8ded4379c89c6ebf1a8e6fc656092af93fb39f421
|
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
@@ -1,44 +1,70 @@
|
|
1
1
|
appraise "rails30" do
|
2
|
+
gem 'rake', '~> 10.5'
|
2
3
|
gem 'rubysl', '~> 2.0', :platforms => :rbx
|
3
4
|
gem 'rubinius-developer_tools', :platforms => :rbx
|
4
|
-
gem 'sqlite3', '1.3.
|
5
|
+
gem 'sqlite3', '1.3.11' , :platforms => [:ruby, :rbx]
|
6
|
+
gem 'i18n', '~> 0.5.0'
|
5
7
|
gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
|
6
8
|
|
7
9
|
gem "activerecord", "~> 3.0.11"
|
10
|
+
|
11
|
+
group :development do
|
12
|
+
gem 'guard', '~> 1.8.3'
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
10
16
|
appraise "rails31" do
|
17
|
+
gem 'rake', '~> 10.5'
|
11
18
|
gem 'rubysl', '~> 2.0', :platforms => :rbx
|
12
19
|
gem 'rubinius-developer_tools', :platforms => :rbx
|
13
|
-
gem 'sqlite3', '1.3.
|
20
|
+
gem 'sqlite3', '1.3.11' , :platforms => [:ruby, :rbx]
|
21
|
+
gem 'i18n', '~> 0.6.0'
|
14
22
|
gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
|
15
23
|
|
16
24
|
gem "activerecord", "~> 3.1.12"
|
25
|
+
|
26
|
+
group :development do
|
27
|
+
gem 'guard', '~> 1.8.3'
|
28
|
+
end
|
17
29
|
end
|
18
30
|
|
19
31
|
appraise "rails32" do
|
32
|
+
gem 'rake', '~> 10.5'
|
20
33
|
gem 'rubysl', '~> 2.0', :platforms => :rbx
|
21
34
|
gem 'rubinius-developer_tools', :platforms => :rbx
|
22
|
-
gem 'sqlite3', '1.3.
|
35
|
+
gem 'sqlite3', '1.3.11' , :platforms => [:ruby, :rbx]
|
36
|
+
gem 'i18n', '~> 0.6.0'
|
23
37
|
gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
|
24
38
|
|
25
39
|
gem "activerecord", "~> 3.2.14"
|
40
|
+
|
41
|
+
group :development do
|
42
|
+
gem 'guard', '~> 1.8.3'
|
43
|
+
end
|
26
44
|
end
|
27
45
|
|
28
46
|
appraise "rails40" do
|
29
47
|
gem 'rubysl', '~> 2.0', :platforms => :rbx
|
30
48
|
gem 'rubinius-developer_tools', :platforms => :rbx
|
31
|
-
gem 'sqlite3', '1.3.
|
49
|
+
gem 'sqlite3', '1.3.11' , :platforms => [:ruby, :rbx]
|
32
50
|
gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
|
33
51
|
|
34
52
|
gem "activerecord", "~> 4.0.0"
|
53
|
+
|
54
|
+
group :development do
|
55
|
+
gem 'guard', '2.12.6'
|
56
|
+
end
|
35
57
|
end
|
36
58
|
|
37
59
|
appraise "rails41" do
|
38
60
|
gem 'rubysl', '~> 2.0', :platforms => :rbx
|
39
61
|
gem 'rubinius-developer_tools', :platforms => :rbx
|
40
|
-
gem 'sqlite3', '1.3.
|
62
|
+
gem 'sqlite3', '1.3.11' , :platforms => [:ruby, :rbx]
|
41
63
|
gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
|
42
64
|
|
43
65
|
gem "activerecord", "~> 4.1.0"
|
66
|
+
|
67
|
+
group :development do
|
68
|
+
gem 'guard', '2.12.6'
|
69
|
+
end
|
44
70
|
end
|
data/Gemfile
CHANGED
@@ -2,8 +2,7 @@ source "http://rubygems.org"
|
|
2
2
|
|
3
3
|
gem 'rubysl', '~> 2.0', :platforms => :rbx
|
4
4
|
gem 'rubinius-developer_tools', :platforms => :rbx
|
5
|
-
gem 'sqlite3',
|
6
|
-
gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
|
5
|
+
gem 'sqlite3', :platforms => [:ruby, :rbx]
|
7
6
|
|
8
7
|
group :development do
|
9
8
|
gem 'guard'
|
data/Readme.md
CHANGED
@@ -79,6 +79,22 @@ event.status_available? # when prefix true
|
|
79
79
|
event.type_company? # you can set a specific name for your prefix
|
80
80
|
```
|
81
81
|
|
82
|
+
#### :constant
|
83
|
+
By default, a constant is created on the class, containing the enum values.
|
84
|
+
You can remove the constant by passing a falsy value (i.e: `nil`, `false`) or rename it by passing a symbol or a string with a different name.
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
class Event < ActiveRecord::Base
|
88
|
+
enum :status, [:available, :canceled, :completed]
|
89
|
+
enum :without_const, [:foo, :bar], :constant => false
|
90
|
+
enum :custom_name, [:a, :b, :c], :constant => :special_name
|
91
|
+
end
|
92
|
+
|
93
|
+
event::STATUSES # returns [:available, :canceled, :completed]
|
94
|
+
event::WITHOUT_CONST # raises NameError
|
95
|
+
event::SPECIAL_NAME # returns [:a, :b, :c]. Note the name was not pluralized.
|
96
|
+
event::CUSTOM_NAME # raises NameError
|
97
|
+
```
|
82
98
|
|
83
99
|
## Callbacks
|
84
100
|
Another cool feature of enumify is the option to add a callback function that will be called each time the value of the field changes
|
data/gemfiles/rails30.gemfile
CHANGED
@@ -4,8 +4,16 @@ source "http://rubygems.org"
|
|
4
4
|
|
5
5
|
gem "rubysl", "~> 2.0", :platforms => :rbx
|
6
6
|
gem "rubinius-developer_tools", :platforms => :rbx
|
7
|
-
gem "sqlite3", "1.3.
|
7
|
+
gem "sqlite3", "1.3.11", :platforms => [:ruby, :rbx]
|
8
|
+
gem "rake", "~> 10.5"
|
9
|
+
gem "i18n", "~> 0.5.0"
|
8
10
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
9
11
|
gem "activerecord", "~> 3.0.11"
|
10
12
|
|
13
|
+
group :development do
|
14
|
+
gem "guard", "~> 1.8.3"
|
15
|
+
gem "guard-rspec"
|
16
|
+
gem "terminal-notifier-guard"
|
17
|
+
end
|
18
|
+
|
11
19
|
gemspec :path => "../"
|
data/gemfiles/rails31.gemfile
CHANGED
@@ -4,8 +4,16 @@ source "http://rubygems.org"
|
|
4
4
|
|
5
5
|
gem "rubysl", "~> 2.0", :platforms => :rbx
|
6
6
|
gem "rubinius-developer_tools", :platforms => :rbx
|
7
|
-
gem "sqlite3", "1.3.
|
7
|
+
gem "sqlite3", "1.3.11", :platforms => [:ruby, :rbx]
|
8
|
+
gem "rake", "~> 10.5"
|
9
|
+
gem "i18n", "~> 0.6.0"
|
8
10
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
9
11
|
gem "activerecord", "~> 3.1.12"
|
10
12
|
|
13
|
+
group :development do
|
14
|
+
gem "guard", "~> 1.8.3"
|
15
|
+
gem "guard-rspec"
|
16
|
+
gem "terminal-notifier-guard"
|
17
|
+
end
|
18
|
+
|
11
19
|
gemspec :path => "../"
|
data/gemfiles/rails32.gemfile
CHANGED
@@ -4,8 +4,16 @@ source "http://rubygems.org"
|
|
4
4
|
|
5
5
|
gem "rubysl", "~> 2.0", :platforms => :rbx
|
6
6
|
gem "rubinius-developer_tools", :platforms => :rbx
|
7
|
-
gem "sqlite3", "1.3.
|
7
|
+
gem "sqlite3", "1.3.11", :platforms => [:ruby, :rbx]
|
8
|
+
gem "rake", "~> 10.5"
|
9
|
+
gem "i18n", "~> 0.6.0"
|
8
10
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
9
11
|
gem "activerecord", "~> 3.2.14"
|
10
12
|
|
13
|
+
group :development do
|
14
|
+
gem "guard", "~> 1.8.3"
|
15
|
+
gem "guard-rspec"
|
16
|
+
gem "terminal-notifier-guard"
|
17
|
+
end
|
18
|
+
|
11
19
|
gemspec :path => "../"
|
data/gemfiles/rails40.gemfile
CHANGED
@@ -4,8 +4,14 @@ source "http://rubygems.org"
|
|
4
4
|
|
5
5
|
gem "rubysl", "~> 2.0", :platforms => :rbx
|
6
6
|
gem "rubinius-developer_tools", :platforms => :rbx
|
7
|
-
gem "sqlite3", "1.3.
|
7
|
+
gem "sqlite3", "1.3.11", :platforms => [:ruby, :rbx]
|
8
8
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
9
9
|
gem "activerecord", "~> 4.0.0"
|
10
10
|
|
11
|
+
group :development do
|
12
|
+
gem "guard", "2.12.6"
|
13
|
+
gem "guard-rspec"
|
14
|
+
gem "terminal-notifier-guard"
|
15
|
+
end
|
16
|
+
|
11
17
|
gemspec :path => "../"
|
data/gemfiles/rails41.gemfile
CHANGED
@@ -4,8 +4,14 @@ source "http://rubygems.org"
|
|
4
4
|
|
5
5
|
gem "rubysl", "~> 2.0", :platforms => :rbx
|
6
6
|
gem "rubinius-developer_tools", :platforms => :rbx
|
7
|
-
gem "sqlite3", "1.3.
|
7
|
+
gem "sqlite3", "1.3.11", :platforms => [:ruby, :rbx]
|
8
8
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
9
9
|
gem "activerecord", "~> 4.1.0"
|
10
10
|
|
11
|
+
group :development do
|
12
|
+
gem "guard", "2.12.6"
|
13
|
+
gem "guard-rspec"
|
14
|
+
gem "terminal-notifier-guard"
|
15
|
+
end
|
16
|
+
|
11
17
|
gemspec :path => "../"
|
data/lib/enumify/model.rb
CHANGED
@@ -18,7 +18,12 @@ module Enumify
|
|
18
18
|
prefix = "#{opts[:prefix].to_s}_"
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
constant = opts.fetch(:constant, true)
|
22
|
+
if constant
|
23
|
+
const_name = constant === true ? paramater_string.pluralize : constant.to_s
|
24
|
+
|
25
|
+
const_set(const_name.upcase, vals)
|
26
|
+
end
|
22
27
|
|
23
28
|
define_method "#{paramater_string}" do
|
24
29
|
attr = read_attribute(parameter)
|
data/lib/enumify/version.rb
CHANGED
data/spec/enumify/enum_spec.rb
CHANGED
@@ -197,8 +197,54 @@ describe :Enumify do
|
|
197
197
|
|
198
198
|
end
|
199
199
|
|
200
|
-
|
201
|
-
|
200
|
+
describe 'constant' do
|
201
|
+
class ModelWithoutConst < ActiveRecord::Base
|
202
|
+
include Enumify::Model
|
203
|
+
self.table_name = 'models'
|
204
|
+
enum :status, [:available, :canceled, :completed], :constant => false
|
205
|
+
end
|
206
|
+
|
207
|
+
class ModelWithSymbolNamedConst < ActiveRecord::Base
|
208
|
+
include Enumify::Model
|
209
|
+
self.table_name = 'models'
|
210
|
+
enum :status, [:available, :canceled, :completed], :constant => :special_status
|
211
|
+
end
|
212
|
+
|
213
|
+
class ModelWithStringNamedConst < ActiveRecord::Base
|
214
|
+
include Enumify::Model
|
215
|
+
self.table_name = 'models'
|
216
|
+
enum :status, [:available, :canceled, :completed], :constant => 'special_status'
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'class should have a CONST that holds all the available options of the enum by default' do
|
220
|
+
expect(Model::STATUSES).to eq [:available, :canceled, :completed]
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'should allow disabling CONST creation' do
|
224
|
+
expect { ModelWithoutConst::STATUSES }.to raise_error(NameError)
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'should allow custom naming of CONST' do
|
228
|
+
expect { ModelWithSymbolNamedConst::SPECIAL_STATUS }.to_not raise_error
|
229
|
+
expect { ModelWithStringNamedConst::SPECIAL_STATUS }.to_not raise_error
|
230
|
+
|
231
|
+
expect(ModelWithSymbolNamedConst::SPECIAL_STATUS).to eq [:available, :canceled, :completed]
|
232
|
+
expect(ModelWithStringNamedConst::SPECIAL_STATUS).to eq [:available, :canceled, :completed]
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'should fail to create CONST with invalid name' do
|
236
|
+
invalid_names = %w([] {} _ 1 . ; test; te^st $test)
|
237
|
+
|
238
|
+
invalid_names.each do |invalid_name|
|
239
|
+
expect {
|
240
|
+
Class.new(ActiveRecord::Base) {
|
241
|
+
include Enumify::Model
|
242
|
+
self.table_name = 'models'
|
243
|
+
enum :status, [:available, :canceled, :completed], :constant => invalid_name
|
244
|
+
}
|
245
|
+
}.to raise_error(NameError)
|
246
|
+
end
|
247
|
+
end
|
202
248
|
end
|
203
249
|
|
204
250
|
describe 'prefix' do
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activerecord
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: appraisal
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.3.8
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.3.8
|
69
69
|
description: |2
|
@@ -80,9 +80,9 @@ executables: []
|
|
80
80
|
extensions: []
|
81
81
|
extra_rdoc_files: []
|
82
82
|
files:
|
83
|
-
- .gitignore
|
84
|
-
- .rspec
|
85
|
-
- .travis.yml
|
83
|
+
- ".gitignore"
|
84
|
+
- ".rspec"
|
85
|
+
- ".travis.yml"
|
86
86
|
- Appraisals
|
87
87
|
- CHANGELOG.md
|
88
88
|
- Gemfile
|
@@ -112,17 +112,17 @@ require_paths:
|
|
112
112
|
- lib
|
113
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
119
|
requirements:
|
120
|
-
- -
|
120
|
+
- - ">="
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: '0'
|
123
123
|
requirements: []
|
124
124
|
rubyforge_project: enumify
|
125
|
-
rubygems_version: 2.
|
125
|
+
rubygems_version: 2.5.1
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: enumify adds an enum command to all ActiveRecord models which enables you
|