magic_enum 1.0.0.beta1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,7 @@ rvm:
3
3
  - 1.8.7
4
4
  - 1.9.3
5
5
  - 2.0.0
6
+ - 2.1.0
6
7
 
7
8
  env:
8
9
  - "RAILS_VERSION=2.2.0"
@@ -25,6 +26,10 @@ matrix:
25
26
  env: "RAILS_VERSION=2.2.0"
26
27
  - rvm: 2.0.0
27
28
  env: "RAILS_VERSION=2.3.0"
29
+ - rvm: 2.1.0
30
+ env: "RAILS_VERSION=2.2.0"
31
+ - rvm: 2.1.0
32
+ env: "RAILS_VERSION=2.3.0"
28
33
 
29
34
  notifications:
30
35
  recipients:
@@ -9,6 +9,7 @@ Features:
9
9
  Bugfixes:
10
10
 
11
11
  - Fixed const naming: use `SIMPLE_STATUSES` and `SIMPLE_STATUSES_INVERTED` instead of `SimpleStatuses` and `SimpleStatusesInverted`
12
+ - Fixed Ruby warning about redefining a constant occurred when two or more magic enums share single enum value hash
12
13
 
13
14
  ## 0.9.0 (August 8, 2013)
14
15
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Travis-CI build status](https://secure.travis-ci.org/kovyrin/magic-enum.png)](http://travis-ci.org/kovyrin/magic-enum)
4
4
 
5
- MagicEnum is a simple ActiveRecord plugin that makes it easier to maintain ENUM-like attributes in your models.
5
+ MagicEnum is a simple ActiveRecord gem that makes it easier to maintain ENUM-like attributes in your models.
6
6
 
7
7
  Examples:
8
8
 
@@ -26,6 +26,14 @@ Name of inverted hash was changed as well:
26
26
  StatusesInverted => STATUSES_INVERTED
27
27
  SimpleStatusesInverted => SIMPLE_STATUSES_INVERTED
28
28
 
29
+ ## Installation
30
+
31
+ Add the "magic_enum" gem to your `Gemfile`.
32
+
33
+ gem "magic_enum"
34
+
35
+ And run `bundle install` command.
36
+
29
37
  ## How to Use
30
38
 
31
39
  Before using `define_enum`, you should define constant with ENUM options.
@@ -112,7 +112,12 @@ module MagicEnum
112
112
  end.first
113
113
  end
114
114
 
115
- const_set(enum_inverted, enum_value.invert)
115
+ enum_inverted_value = enum_value.invert
116
+ if !const_defined?(enum_inverted)
117
+ const_set(enum_inverted, enum_value.invert)
118
+ elsif const_get(enum_inverted) != enum_inverted_value
119
+ raise ArgumentError, "Inverted enum constant \"#{enum_inverted}\" is already defined and contains wrong values"
120
+ end
116
121
 
117
122
  class_eval <<-RUBY
118
123
  def self.#{name}_value(name)
@@ -4,7 +4,7 @@ module MagicEnum
4
4
  MAJOR = 1
5
5
  MINOR = 0
6
6
  PATCH = 0
7
- BUILD = 'beta1'
7
+ BUILD = nil
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
10
10
  end
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.homepage = 'https://github.com/kovyrin/magic-enum'
13
13
  s.summary = 'ActiveRecord plugin that makes it easier to maintain ENUM-like attributes in your models'
14
14
  s.description = 'MagicEnum is a simple ActiveRecord plugin that makes it easier to maintain ENUM-like attributes in your models.'
15
+ s.license = 'MIT'
15
16
 
16
17
  s.rdoc_options = [ '--charset=UTF-8' ]
17
18
 
@@ -318,6 +318,27 @@ describe 'Model with magic enum and enum option specified' do
318
318
  end
319
319
  end
320
320
 
321
+ describe 'Model with two magic enums sharing a single enum hash' do
322
+ include MagicEnumHelper
323
+
324
+ class TestModelSimple < MagicEnumHelper::TestModelBase
325
+ define_enum :status
326
+ define_enum :another_status, :enum => 'STATUSES'
327
+ end
328
+
329
+ before do
330
+ @model = TestModelSimple.new
331
+ end
332
+
333
+ it 'should define helper class methods' do
334
+ expect(TestModelSimple.status_value(:draft)).to eq(1)
335
+ expect(TestModelSimple.another_status_value(:draft)).to eq(1)
336
+
337
+ expect(TestModelSimple.status_by_value(1)).to eq(:draft)
338
+ expect(TestModelSimple.another_status_by_value(1)).to eq(:draft)
339
+ end
340
+ end
341
+
321
342
  describe 'ActiveRecord::Base class' do
322
343
  it 'should include MagicEnum methods' do
323
344
  expect(ActiveRecord::Base).to respond_to(:define_enum)
metadata CHANGED
@@ -1,95 +1,104 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: magic_enum
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
5
11
  platform: ruby
6
- authors:
12
+ authors:
7
13
  - Dmytro Shteflyuk
8
14
  - Oleksiy Kovyrin
9
15
  autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
- date: 2013-11-12 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
18
+
19
+ date: 2014-04-01 00:00:00 -04:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
15
23
  name: activerecord
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - '>='
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :runtime
22
24
  prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - '>='
26
- - !ruby/object:Gem::Version
27
- version: '0'
28
- - !ruby/object:Gem::Dependency
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
29
37
  name: rspec
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - '>='
33
- - !ruby/object:Gem::Version
34
- version: '0'
35
- type: :development
36
38
  prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - '>='
40
- - !ruby/object:Gem::Version
41
- version: '0'
42
- - !ruby/object:Gem::Dependency
43
- name: rake
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - '>='
47
- - !ruby/object:Gem::Version
48
- version: '0'
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
49
48
  type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rake
50
52
  prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - '>='
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
- - !ruby/object:Gem::Dependency
57
- name: rdoc
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - '>='
61
- - !ruby/object:Gem::Version
62
- version: '0'
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
63
62
  type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: rdoc
64
66
  prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- - !ruby/object:Gem::Dependency
71
- name: yard
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - '>='
75
- - !ruby/object:Gem::Version
76
- version: '0'
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
77
76
  type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: yard
78
80
  prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - '>='
82
- - !ruby/object:Gem::Version
83
- version: '0'
84
- description: MagicEnum is a simple ActiveRecord plugin that makes it easier to maintain
85
- ENUM-like attributes in your models.
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id005
92
+ description: MagicEnum is a simple ActiveRecord plugin that makes it easier to maintain ENUM-like attributes in your models.
86
93
  email: alexey@kovyrin.net
87
94
  executables: []
95
+
88
96
  extensions: []
89
- extra_rdoc_files:
97
+
98
+ extra_rdoc_files:
90
99
  - LICENSE
91
100
  - README.md
92
- files:
101
+ files:
93
102
  - .gitignore
94
103
  - .travis.yml
95
104
  - CHANGELOG.md
@@ -102,30 +111,39 @@ files:
102
111
  - lib/magic_enum/version.rb
103
112
  - magic_enum.gemspec
104
113
  - spec/magic_enum_spec.rb
114
+ has_rdoc: true
105
115
  homepage: https://github.com/kovyrin/magic-enum
106
- licenses: []
107
- metadata: {}
116
+ licenses:
117
+ - MIT
108
118
  post_install_message:
109
- rdoc_options:
119
+ rdoc_options:
110
120
  - --charset=UTF-8
111
- require_paths:
121
+ require_paths:
112
122
  - lib
113
- required_ruby_version: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- required_rubygems_version: !ruby/object:Gem::Requirement
119
- requirements:
120
- - - '>'
121
- - !ruby/object:Gem::Version
122
- version: 1.3.1
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ hash: 3
129
+ segments:
130
+ - 0
131
+ version: "0"
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ hash: 3
138
+ segments:
139
+ - 0
140
+ version: "0"
123
141
  requirements: []
142
+
124
143
  rubyforge_project:
125
- rubygems_version: 2.1.9
144
+ rubygems_version: 1.5.2
126
145
  signing_key:
127
- specification_version: 4
128
- summary: ActiveRecord plugin that makes it easier to maintain ENUM-like attributes
129
- in your models
146
+ specification_version: 3
147
+ summary: ActiveRecord plugin that makes it easier to maintain ENUM-like attributes in your models
130
148
  test_files: []
131
- has_rdoc:
149
+
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: cdd3250404ebdecd1fdb9aeb525cfdc5bbdf8a94
4
- data.tar.gz: 6df523ae0550f389ef112b0d9d598d8e477819a8
5
- SHA512:
6
- metadata.gz: 80c0eefee215b74e86e003ebf4962fa4f35a513309197f10ecab2822ad574c84bbcc0da3e11ddfed334f9e205033188a56a0090c1956ea100b1fd7c7aeb43d93
7
- data.tar.gz: a42a06ade03d296c9fb75cf46e42c06ad1c0d58f4cb9e28778bfbfacb60c1bdbbb114fb59c79e438fc5e0702ae644c7368d0d3763f3d59f6f7fa1a270495b30a