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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e186a8d9675c9e5b1959d6bda11d3883329a8b96
4
- data.tar.gz: 122e5bdcb684221bb5c2d585fa7e79af75506e0e
3
+ metadata.gz: 635791d1c61f10feee7cebf75a2be9a06ff95a20
4
+ data.tar.gz: 37859ccd1e25feb2789a52a151cf4fb5194e9596
5
5
  SHA512:
6
- metadata.gz: 9a728aa7bed29637d532075d31611d9224cb55c27fc467594eb4d4a15c632146401b1ea48d647198223c205e0ee5af729bb1a1bc124b6a24ef4f353bc0b2cde3
7
- data.tar.gz: 674ca49a2f592cd96dcb5abe9d2d6a8129ae025d21d5ceeb66a108b3473722272792e61bbd40fceec74e4aec2d9c82ca0b8eb0af654be958ee3db76c9c455952
6
+ metadata.gz: f9061022d1e98c0c006b3969041d48e6af15bf5df51ffa516c4d2c75e2e755945a70ae4e4d8b1838288f50f52efe9669f83d6958ecf76679e524e35a7e152b4e
7
+ data.tar.gz: 2ab5669fade3bdebd803c55838a0dee632b70632d15f324aa239ee5003cfd8e01e2f71478ca0739969087ed8ded4379c89c6ebf1a8e6fc656092af93fb39f421
data/.travis.yml CHANGED
@@ -12,6 +12,8 @@ gemfile:
12
12
  - gemfiles/rails32.gemfile
13
13
  - gemfiles/rails40.gemfile
14
14
  - gemfiles/rails41.gemfile
15
+ before_install:
16
+ - "if [ ${TRAVIS_RUBY_VERSION:-''} = '1.9.3' ]; then gem install bundler; fi"
15
17
  matrix:
16
18
  exclude:
17
19
  - rvm: 1.8.7
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.8' , :platforms => [:ruby, :rbx]
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.8' , :platforms => [:ruby, :rbx]
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.8' , :platforms => [:ruby, :rbx]
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.8' , :platforms => [:ruby, :rbx]
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.8' , :platforms => [:ruby, :rbx]
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', '1.3.8', :platforms => [:ruby, :rbx]
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
@@ -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.8", :platforms => [:ruby, :rbx]
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 => "../"
@@ -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.8", :platforms => [:ruby, :rbx]
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 => "../"
@@ -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.8", :platforms => [:ruby, :rbx]
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 => "../"
@@ -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.8", :platforms => [:ruby, :rbx]
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 => "../"
@@ -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.8", :platforms => [:ruby, :rbx]
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
- const_set("#{paramater_string.pluralize.upcase}", vals)
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)
@@ -1,3 +1,3 @@
1
1
  module Enumify
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -197,8 +197,54 @@ describe :Enumify do
197
197
 
198
198
  end
199
199
 
200
- it "class should have a CONST that holds all the available options of the enum" do
201
- expect(Model::STATUSES).to eq [:available, :canceled, :completed]
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.1.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: 2014-09-26 00:00:00.000000000 Z
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.4.0
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