enum_table 0.5.0 → 0.6.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/.travis.yml +1 -1
- data/CHANGELOG +5 -0
- data/Gemfile +2 -2
- data/Gemfile.ar3 +2 -2
- data/README.markdown +10 -0
- data/Rakefile +3 -0
- data/enum_table.gemspec +1 -1
- data/lib/enum_table/record.rb +6 -0
- data/lib/enum_table/version.rb +1 -1
- data/test/enum_table/test_record.rb +23 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 454b43bc909062242f9bd1efbb13e93e5538a172
|
4
|
+
data.tar.gz: 2fc187f19fd7be548a9eee563cacd63ad4367e5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1630c5db844ab64dbc0ffae78cb73a6b60e6288f410d2f152e1b8a2d558fbd86e03b5b052498f12fb241e2b57e57dd67a26f13f35bd149030861550e809470b2
|
7
|
+
data.tar.gz: dd6ae8b8f66ea98a1f99731cf3bc9b421b8cdd41d415cdfdf27e0aeeaa2f20d4ef8d25e2c886b161eb15f1c460d018064bb979eb6184ad0d14f4489366cc5a50
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
data/Gemfile
CHANGED
data/Gemfile.ar3
CHANGED
data/README.markdown
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
Table-based enumerations for ActiveRecord.
|
4
4
|
|
5
|
+
## Deprecation Notice
|
6
|
+
|
7
|
+
ActiveRecord 4.1 introduced its own way of handling enumerations, which is
|
8
|
+
somewhat at odds with the approach of this gem. To get the additional benefits
|
9
|
+
of Enum Table, it's suggested that you migrate to standard ActiveRecord enums,
|
10
|
+
and then sync the enum values in your code to your database as necessary.
|
11
|
+
|
12
|
+
Enum Table is compatible with ActiveRecord versions up to 4.1.x, but 4.2.x
|
13
|
+
support is not currently planned.
|
14
|
+
|
5
15
|
## What?
|
6
16
|
|
7
17
|
When you have a column that should only take one of a finite set of string
|
data/Rakefile
CHANGED
data/enum_table.gemspec
CHANGED
@@ -15,6 +15,6 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.files = `git ls-files`.split("\n")
|
16
16
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
17
|
|
18
|
-
gem.add_runtime_dependency 'activerecord', '>= 3', '<
|
18
|
+
gem.add_runtime_dependency 'activerecord', '>= 3', '< 4.2'
|
19
19
|
gem.add_development_dependency 'ritual', '~> 0.4.1'
|
20
20
|
end
|
data/lib/enum_table/record.rb
CHANGED
@@ -80,6 +80,12 @@ module EnumTable
|
|
80
80
|
reflection.id(value)
|
81
81
|
end
|
82
82
|
|
83
|
+
def enum_value(name, id)
|
84
|
+
reflection = enums[name] or
|
85
|
+
raise ArgumentError, "no such enum: #{name}"
|
86
|
+
reflection.value(id)
|
87
|
+
end
|
88
|
+
|
83
89
|
# Enables enums for STI types.
|
84
90
|
def builtin_inheritance_column # :nodoc:
|
85
91
|
# Can this be made less brittle?
|
data/lib/enum_table/version.rb
CHANGED
@@ -170,12 +170,32 @@ describe EnumTable do
|
|
170
170
|
describe ".enum_id" do
|
171
171
|
before { User.enum :gender, table: {female: 1} }
|
172
172
|
|
173
|
+
it "returns the id for the given enum value" do
|
174
|
+
User.enum_id(:gender, :female).must_equal 1
|
175
|
+
end
|
176
|
+
|
177
|
+
it "returns nil if the value is invalid" do
|
178
|
+
User.enum_id(:gender, :bad).must_be_nil
|
179
|
+
end
|
180
|
+
|
173
181
|
it "raises an ArgumentError if the enum name is invalid" do
|
174
|
-
->{ User.enum_id(:
|
182
|
+
->{ User.enum_id(:bender, :female) }.must_raise ArgumentError
|
175
183
|
end
|
184
|
+
end
|
176
185
|
|
177
|
-
|
178
|
-
|
186
|
+
describe ".enum_value" do
|
187
|
+
before { User.enum :gender, table: {female: 1} }
|
188
|
+
|
189
|
+
it "returns the value for the given enum id" do
|
190
|
+
User.enum_value(:gender, 1).must_equal :female
|
191
|
+
end
|
192
|
+
|
193
|
+
it "raises nil if the enum id is invalid" do
|
194
|
+
User.enum_value(:gender, 3).must_be_nil
|
195
|
+
end
|
196
|
+
|
197
|
+
it "raises an ArgumentError if the enum name is invalid" do
|
198
|
+
->{ User.enum_value(:bender, 1) }.must_raise ArgumentError
|
179
199
|
end
|
180
200
|
end
|
181
201
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enum_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- George Ogata
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '3'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '4.2'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '3'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '4.2'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: ritual
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.4.5
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Enumeration tables for ActiveRecord
|