enum_table 0.5.0 → 0.6.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: 9efb4a2edbe205dac4da12d14820d33a78ddb91f
4
- data.tar.gz: 8f4aeb6cbc9ae4455bd2efaefbc7e0a16342d31a
3
+ metadata.gz: 454b43bc909062242f9bd1efbb13e93e5538a172
4
+ data.tar.gz: 2fc187f19fd7be548a9eee563cacd63ad4367e5e
5
5
  SHA512:
6
- metadata.gz: 678a59b0aedd78bcd0ef41b501bf9dfb7e093fee99e348c607353cb812f93ee5d36bcf70827e3b8f291b3eee65fa463c846bbc486e6007c09d19396097eaaa57
7
- data.tar.gz: 18c93a939a2a712412133779b92a4f39a4154e8c1b9646d41c9da2087c8aac9d824a778cf090b417f64214f98d96c683b6253d18cbdc599e05918f9e6bf20c13
6
+ metadata.gz: 1630c5db844ab64dbc0ffae78cb73a6b60e6288f410d2f152e1b8a2d558fbd86e03b5b052498f12fb241e2b57e57dd67a26f13f35bd149030861550e809470b2
7
+ data.tar.gz: dd6ae8b8f66ea98a1f99731cf3bc9b421b8cdd41d415cdfdf27e0aeeaa2f20d4ef8d25e2c886b161eb15f1c460d018064bb979eb6184ad0d14f4489366cc5a50
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  bundler_args: --without dev
3
- script: bundle exec testrb test
3
+ script: bundle exec rake test
4
4
  rvm:
5
5
  - 2.0.0
6
6
  - 2.1.0
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.6.0 2015-03-06
2
+
3
+ * Add Thing.enum_value, as the inverse of Thing.enum_id.
4
+ * Fix ActiveRecord version dependency. 4.2 is not supported.
5
+
1
6
  == 0.5.0 2014-03-26
2
7
 
3
8
  * Rails 4 support.
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
1
  source 'https://rubygems.org'
2
- gem 'activerecord'
2
+ gem 'activerecord', '~> 4.1.0'
3
3
  gem 'sqlite3'
4
4
  gem 'mysql2'
5
5
  gem 'pg'
6
- gem 'minitest', '~> 4.0'
6
+ gem 'minitest', '~> 5'
7
7
  gemspec
8
8
 
9
9
  group :dev do
@@ -1,9 +1,9 @@
1
1
  source 'https://rubygems.org'
2
- gem 'activerecord', '~> 3'
2
+ gem 'activerecord', '~> 3.2'
3
3
  gem 'sqlite3'
4
4
  gem 'mysql2'
5
5
  gem 'pg'
6
- gem 'minitest', '~> 4.0'
6
+ gem 'minitest', '~> 5'
7
7
  gemspec
8
8
 
9
9
  group :dev do
@@ -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
@@ -1 +1,4 @@
1
1
  require 'ritual'
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new(:test) { |t| t.pattern = 'test/**/*.rb' }
@@ -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', '< 5'
18
+ gem.add_runtime_dependency 'activerecord', '>= 3', '< 4.2'
19
19
  gem.add_development_dependency 'ritual', '~> 0.4.1'
20
20
  end
@@ -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?
@@ -1,5 +1,5 @@
1
1
  module EnumTable
2
- VERSION = [0, 5, 0]
2
+ VERSION = [0, 6, 0]
3
3
 
4
4
  class << VERSION
5
5
  include Comparable
@@ -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(:bad) }.must_raise ArgumentError
182
+ ->{ User.enum_id(:bender, :female) }.must_raise ArgumentError
175
183
  end
184
+ end
176
185
 
177
- it "returns the id for the given enum value" do
178
- User.enum_id(:gender, :female).must_equal 1
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.5.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: 2014-03-26 00:00:00.000000000 Z
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: '5'
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: '5'
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.2.2
96
+ rubygems_version: 2.4.5
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: Enumeration tables for ActiveRecord