simple_enum 1.6.8 → 1.6.9

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: f6a68b2d21b025bcb22c251918ff51b412be8ab6
4
- data.tar.gz: bbe02918d4165d9bca1917c7dc38981bc0127136
3
+ metadata.gz: 18d5bbe70d30e114c220f17681c172597163bfd0
4
+ data.tar.gz: e9ae250d080b7f6efa78928005df4b9f36ca9ffb
5
5
  SHA512:
6
- metadata.gz: 4ce5b6271ff2a6b391819e544901d2ddfcfd64ff5c6c253b5f28cdafa94e169f9d2baa6ea7bfd0e35e03e270a63c36d8c4fa6c4f878f8926861d67f63fea0a4d
7
- data.tar.gz: 91ad1ead6ee168f5fdcd08f82f004a232dcd1d48a8406a08f3b7597f000d8c96f0d2b7f10099f1ef0a00d4a099d32c19516fa81310aa532a43db8cd62d938e62
6
+ metadata.gz: 9150ad6487da910c1b6319030102a2e8504f0775e995f2e4cc8ca09e6198e91176e08d6fa8b9aca468aa0de43cdb5a4168d7b802c0ca159d2a98b860810666a7
7
+ data.tar.gz: 14577d002d9996148f4e321624ecaba8cf705de2ff8162f06c5aca7940b620dfbf1cda88c3c182aa10eed11ce8257d129e4cc4f870a77f123c0b996a86f97205
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ pkg
6
6
  .*.sw?
7
7
  tmp
8
8
  Gemfile.lock
9
+ :memory*
data/Gemfile CHANGED
@@ -2,8 +2,10 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
+ # Fix at 1.9.x, because 1.10 errors on jruby
6
+ gem 'mongo', '~> 1.9.0', :platform => :jruby
7
+
5
8
  # some development deps
6
9
  gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
7
-
8
10
  gem 'sqlite3', :platform => :ruby
9
11
  gem 'bson_ext', :platform => :ruby
data/README.rdoc CHANGED
@@ -85,7 +85,7 @@ useful when creating queries, displaying option elements or similar:
85
85
  * You can use string values instead of integer values if your database column has the type +string+ or +text+:
86
86
 
87
87
  class User < ActiveRecord::Base
88
- as_eum :status, [:deleted, :active, :dsiabled], :strings => true
88
+ as_enum :status, [:deleted, :active, :disabled], :strings => true
89
89
  end
90
90
 
91
91
  User.create!(status: :active) #=> #<User id: 1, status_cd: "active">
data/lib/simple_enum.rb CHANGED
@@ -182,17 +182,23 @@ module SimpleEnum
182
182
 
183
183
  # generate setter
184
184
  define_method("#{enum_cd}=") do |new_value|
185
- new_value = new_value.to_s if options[:strings] && new_value
186
- real = new_value.blank? ? nil : values[EnumHash.symbolize(new_value)]
187
- real = new_value if real.nil? && values_inverted[new_value].present?
188
- raise(ArgumentError, "Invalid enumeration value: #{new_value}") if (options[:whiny] and real.nil? and !new_value.blank?)
185
+ return send("#{options[:column]}=", nil) if new_value.blank?
186
+
187
+ new_value = new_value.to_s if options[:strings]
188
+ real = nil
189
+ if values.contains?(new_value)
190
+ real = values[EnumHash.symbolize(new_value)]
191
+ real = new_value if real.nil? && values_inverted[new_value].present?
192
+ end
193
+
194
+ raise ArgumentError, "Invalid enumeration value: #{new_value}" if options[:whiny] && !real
189
195
  send("#{options[:column]}=", real)
190
196
  end
191
197
 
192
198
  # generate checker
193
199
  define_method("#{enum_cd}?") do |*args|
194
200
  current = send(enum_cd)
195
- return current == EnumHash.symbolize(args.first) if args.length > 0
201
+ return current.to_s == args.first.to_s if args.length > 0
196
202
 
197
203
  !!current
198
204
  end
@@ -29,6 +29,14 @@ module SimpleEnum
29
29
  ary ||= args
30
30
  ary.each { |e| set_value_for_reverse_lookup(e[0], strings ? e[0].to_s : e[1]) }
31
31
  end
32
+
33
+ @stringified_keys = keys.map(&:to_s)
34
+
35
+ freeze
36
+ end
37
+
38
+ def contains?(value)
39
+ @stringified_keys.include?(value.to_s) || values.include?(value)
32
40
  end
33
41
 
34
42
  def default(k = nil)
@@ -1,5 +1,5 @@
1
1
  module SimpleEnum
2
2
 
3
3
  # +SimpleEnum+ version string.
4
- VERSION = "1.6.8"
4
+ VERSION = "1.6.9"
5
5
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.8
4
+ version: 1.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Westermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-27 00:00:00.000000000 Z
11
+ date: 2014-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.9.2
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.9.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activerecord
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 3.0.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.0.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mongoid
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '2.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.0'
83
83
  description: Provides enum-like fields for ActiveRecord, ActiveModel and Mongoid models.
@@ -87,22 +87,24 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
91
- - Rakefile
90
+ - ".gitignore"
92
91
  - Gemfile
93
- - README.rdoc
94
92
  - LICENSE
95
- - simple_enum.gemspec
93
+ - README.rdoc
94
+ - Rakefile
95
+ - lib/simple_enum.rb
96
96
  - lib/simple_enum/enum_hash.rb
97
97
  - lib/simple_enum/mongoid.rb
98
98
  - lib/simple_enum/validation.rb
99
99
  - lib/simple_enum/version.rb
100
- - lib/simple_enum.rb
100
+ - locales/en.yml
101
+ - simple_enum.gemspec
101
102
  - test/array_conversions_test.rb
102
103
  - test/class_methods_test.rb
103
104
  - test/dirty_attributes_test.rb
104
105
  - test/enum_hash_test.rb
105
106
  - test/finders_test.rb
107
+ - test/locales.yml
106
108
  - test/mongoid_test.rb
107
109
  - test/object_backed_test.rb
108
110
  - test/orm/active_record.rb
@@ -113,8 +115,6 @@ files:
113
115
  - test/simple_enum_test.rb
114
116
  - test/test_helper.rb
115
117
  - test/without_shortcuts_test.rb
116
- - locales/en.yml
117
- - test/locales.yml
118
118
  homepage: http://lwe.github.com/simple_enum/
119
119
  licenses:
120
120
  - MIT
@@ -125,26 +125,28 @@ require_paths:
125
125
  - lib
126
126
  required_ruby_version: !ruby/object:Gem::Requirement
127
127
  requirements:
128
- - - '>='
128
+ - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: 1.8.7
131
131
  required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  requirements:
133
- - - '>='
133
+ - - ">="
134
134
  - !ruby/object:Gem::Version
135
135
  version: 1.3.6
136
136
  requirements: []
137
137
  rubyforge_project:
138
- rubygems_version: 2.0.3
138
+ rubygems_version: 2.2.0
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: Simple enum-like field support for models.
142
142
  test_files:
143
+ - locales/en.yml
143
144
  - test/array_conversions_test.rb
144
145
  - test/class_methods_test.rb
145
146
  - test/dirty_attributes_test.rb
146
147
  - test/enum_hash_test.rb
147
148
  - test/finders_test.rb
149
+ - test/locales.yml
148
150
  - test/mongoid_test.rb
149
151
  - test/object_backed_test.rb
150
152
  - test/orm/active_record.rb
@@ -155,5 +157,3 @@ test_files:
155
157
  - test/simple_enum_test.rb
156
158
  - test/test_helper.rb
157
159
  - test/without_shortcuts_test.rb
158
- - locales/en.yml
159
- - test/locales.yml