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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d19e9c2f8ad9ea3ccf2b81563146a0e5b3101d3
4
- data.tar.gz: ad152874af07e021afb937f992b2214d64ab17ee
3
+ metadata.gz: 85096c24629c9f6d96e11998cfa30bc6da436f18
4
+ data.tar.gz: 31a96a5d457a1c0f2ce9b1f797e8fa0d4c317097
5
5
  SHA512:
6
- metadata.gz: 1d3ba38a2bae5876cca07457b102a77ea338f3cc5cb8ff77062119184c6dac21e0c06ee2c571512239a3633b8bd08d1c9e73e3f1376ac4170918a9057aa365e7
7
- data.tar.gz: e49a3fa11d225029707053525cddbf19f4ec9f65faa18b8bab49e4bd0dce680344f09ba29bfca7ec2ef3886ca77ea22eb332ccdab28c5b48d0148d12060d0cea
6
+ metadata.gz: 7bbdbd90d9bf88a7c3e0b9dd34b155752777f3bb911c9ed547e5da3ccf60a2730e59d1741fbc809f410fd70b1a4347b3ce3d0ec67ffc06901843579dd29c09aa
7
+ data.tar.gz: 07558b62edcfa2795ce0c51ad32e3058210707573274ce9f3d5845a5a6d9ee047eb450d4555f1f1afe78657133d727d13bd53d6050bd1d89f2dda83ee0c81b1f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.1
1
+ 0.9.0
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: degu 0.8.1 ruby lib
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.8.1"
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-02-24"
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.3.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.3.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.3.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"])
@@ -15,20 +15,22 @@ module Degu
15
15
  # end
16
16
  def has_enum(enum_name, options={})
17
17
 
18
- enum_column = options.has_key?(:column_name) ? options[:column_name].to_s : "#{enum_name}_type"
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.has_key?(:class_name) ? options[:class_name].to_s.constantize : enum_name.to_s.camelize.constantize
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
- define_method("reset_enum_changed") do
29
- @enum_changed = false
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 = ((column_definition = self.class.columns_hash[enum_column]) and column_definition.type)
55
- self[enum_column] = case column_type
56
- when :integer
57
- enum_resolved.index
58
- else
59
- enum_resolved.name
60
- end
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
@@ -1,6 +1,6 @@
1
1
  module Degu
2
2
  # Degu version
3
- VERSION = '0.8.1'
3
+ VERSION = '0.9.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -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
@@ -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.8.1
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-02-24 00:00:00.000000000 Z
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.3.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.3.1
26
+ version: 1.7.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: test-unit
29
29
  requirement: !ruby/object:Gem::Requirement