degu 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/degu.gemspec +6 -6
- data/lib/degu/has_enum.rb +20 -12
- data/lib/degu/version.rb +1 -1
- data/test/has_enum_test.rb +11 -0
- data/test/test_helper.rb +17 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85096c24629c9f6d96e11998cfa30bc6da436f18
|
4
|
+
data.tar.gz: 31a96a5d457a1c0f2ce9b1f797e8fa0d4c317097
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bbdbd90d9bf88a7c3e0b9dd34b155752777f3bb911c9ed547e5da3ccf60a2730e59d1741fbc809f410fd70b1a4347b3ce3d0ec67ffc06901843579dd29c09aa
|
7
|
+
data.tar.gz: 07558b62edcfa2795ce0c51ad32e3058210707573274ce9f3d5845a5a6d9ee047eb450d4555f1f1afe78657133d727d13bd53d6050bd1d89f2dda83ee0c81b1f
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.0
|
data/degu.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: degu 0.
|
2
|
+
# stub: degu 0.9.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "degu"
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.9.0"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib"]
|
10
10
|
s.authors = ["Florian Frank"]
|
11
|
-
s.date = "2016-
|
11
|
+
s.date = "2016-06-23"
|
12
12
|
s.description = "Library that includes enums, and rails support for enums and bitfield sets."
|
13
13
|
s.email = "flori@ping.de"
|
14
14
|
s.extra_rdoc_files = ["README.md", "lib/degu.rb", "lib/degu/has_enum.rb", "lib/degu/has_set.rb", "lib/degu/init_active_record_plugins.rb", "lib/degu/polite.rb", "lib/degu/railtie.rb", "lib/degu/renum.rb", "lib/degu/renum/enumerated_value.rb", "lib/degu/renum/enumerated_value_type_factory.rb", "lib/degu/rude.rb", "lib/degu/version.rb"]
|
@@ -23,14 +23,14 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.specification_version = 4
|
24
24
|
|
25
25
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
-
s.add_development_dependency(%q<gem_hadar>, ["~> 1.
|
26
|
+
s.add_development_dependency(%q<gem_hadar>, ["~> 1.7.1"])
|
27
27
|
s.add_development_dependency(%q<test-unit>, [">= 0"])
|
28
28
|
s.add_development_dependency(%q<mocha>, [">= 0"])
|
29
29
|
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
30
30
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
31
31
|
s.add_development_dependency(%q<activerecord>, ["< 5.1", ">= 3.0"])
|
32
32
|
else
|
33
|
-
s.add_dependency(%q<gem_hadar>, ["~> 1.
|
33
|
+
s.add_dependency(%q<gem_hadar>, ["~> 1.7.1"])
|
34
34
|
s.add_dependency(%q<test-unit>, [">= 0"])
|
35
35
|
s.add_dependency(%q<mocha>, [">= 0"])
|
36
36
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
|
|
38
38
|
s.add_dependency(%q<activerecord>, ["< 5.1", ">= 3.0"])
|
39
39
|
end
|
40
40
|
else
|
41
|
-
s.add_dependency(%q<gem_hadar>, ["~> 1.
|
41
|
+
s.add_dependency(%q<gem_hadar>, ["~> 1.7.1"])
|
42
42
|
s.add_dependency(%q<test-unit>, [">= 0"])
|
43
43
|
s.add_dependency(%q<mocha>, [">= 0"])
|
44
44
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
data/lib/degu/has_enum.rb
CHANGED
@@ -15,20 +15,22 @@ module Degu
|
|
15
15
|
# end
|
16
16
|
def has_enum(enum_name, options={})
|
17
17
|
|
18
|
-
enum_column = options.
|
18
|
+
enum_column = options.key?(:column_name) ? options[:column_name].to_s : "#{enum_name}_type"
|
19
19
|
|
20
20
|
self.send("validate", "#{enum_column}_check_for_valid_type_of_enum".to_sym)
|
21
21
|
|
22
22
|
# throws a NameError if Enum Class doesn't exists
|
23
|
-
enum_class = options.
|
23
|
+
enum_class = options.key?(:class_name) ? options[:class_name].to_s.constantize : enum_name.to_s.camelize.constantize
|
24
24
|
|
25
25
|
# Enum must be a Renum::EnumeratedValue Enum
|
26
26
|
raise ArgumentError, "expected Renum::EnumeratedValue" unless enum_class.superclass == Renum::EnumeratedValue
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
if respond_to?(:after_save)
|
29
|
+
define_method("reset_enum_changed") do
|
30
|
+
@enum_changed = false
|
31
|
+
end
|
32
|
+
after_save :reset_enum_changed
|
30
33
|
end
|
31
|
-
after_save :reset_enum_changed
|
32
34
|
|
33
35
|
define_method("#{enum_name}") do
|
34
36
|
begin
|
@@ -51,13 +53,19 @@ module Degu
|
|
51
53
|
if enum_to_set.to_s.strip.empty?
|
52
54
|
self[enum_column] = nil
|
53
55
|
elsif enum_resolved
|
54
|
-
column_type =
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
column_type =
|
57
|
+
if self.class.respond_to?(:columns_hash) and
|
58
|
+
column_definition = self.class.columns_hash[enum_column]
|
59
|
+
then
|
60
|
+
column_definition.type
|
61
|
+
end
|
62
|
+
self[enum_column] =
|
63
|
+
case column_type
|
64
|
+
when :integer
|
65
|
+
enum_resolved.index
|
66
|
+
else
|
67
|
+
enum_resolved.name
|
68
|
+
end
|
61
69
|
else
|
62
70
|
raise ArgumentError, "could not resolve #{enum_to_set.inspect}"
|
63
71
|
end
|
data/lib/degu/version.rb
CHANGED
data/test/has_enum_test.rb
CHANGED
@@ -208,4 +208,15 @@ class HasEnumTest < Test::Unit::TestCase
|
|
208
208
|
assert_equal false, with_integer.valid?
|
209
209
|
end
|
210
210
|
|
211
|
+
def test_should_allow_for_nondb_models
|
212
|
+
without_db = ClassWithoutDb.new
|
213
|
+
without_db.product = Product::Titanium
|
214
|
+
assert_equal 'Titanium', without_db[:product_type]
|
215
|
+
|
216
|
+
without_db[:product_type] = 0
|
217
|
+
assert_equal Product::Silver, without_db.product
|
218
|
+
|
219
|
+
without_db[:product_type] = :gold
|
220
|
+
assert_equal Product::Gold, without_db.product
|
221
|
+
end
|
211
222
|
end
|
data/test/test_helper.rb
CHANGED
@@ -164,6 +164,23 @@ class ClassWithIntergerColumn < ActiveRecord::Base
|
|
164
164
|
has_enum :product
|
165
165
|
end
|
166
166
|
|
167
|
+
class ClassWithoutDb
|
168
|
+
include ActiveModel::Model
|
169
|
+
include Degu::HasEnum
|
170
|
+
|
171
|
+
def [](name)
|
172
|
+
instance_variable_get "@#{name}"
|
173
|
+
end
|
174
|
+
|
175
|
+
def []=(name, value)
|
176
|
+
instance_variable_set "@#{name}", value
|
177
|
+
end
|
178
|
+
|
179
|
+
attr_accessor :product_type
|
180
|
+
|
181
|
+
has_enum :product
|
182
|
+
end
|
183
|
+
|
167
184
|
class ClassWithLargeDataset < ActiveRecord::Base
|
168
185
|
has_set :dataset
|
169
186
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: degu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.7.1
|
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
|
-
version: 1.
|
26
|
+
version: 1.7.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: test-unit
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|