enumerize 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -1
- data/CHANGELOG.md +6 -0
- data/lib/enumerize/attribute.rb +14 -6
- data/lib/enumerize/predicatable.rb +7 -16
- data/lib/enumerize/set.rb +2 -6
- data/lib/enumerize/value.rb +2 -6
- data/lib/enumerize/version.rb +1 -1
- data/test/attribute_test.rb +4 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7430100f0e35ac39085f08ca0dca223b4f101a86
|
4
|
+
data.tar.gz: 5726bf780a70d9cfd67e6c51622c734abd7a9644
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1221db4e0a2377d4123c0d64f3b0fbcf63d549e15963d44562a96d4a68eac0017015fbba7ce4e56bdaf4f6904ca5ab99592fdad70813333cdd52032ae440902c
|
7
|
+
data.tar.gz: dfd016c59f61900a641483df577bf793ce9f6b36f695958d6f9676ef49ed4f54d7cce57e1a2c9936ab8f7f63ee76f9932244d998474cf32677a55671339cc6d8
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,12 @@
|
|
4
4
|
|
5
5
|
### bug fix
|
6
6
|
|
7
|
+
## 0.10.1 (March 4, 2015) ##
|
8
|
+
|
9
|
+
### bug fix
|
10
|
+
|
11
|
+
* Use method_missing instead of defining singleton class methods to allow Marshal serialization (by [@lest](https://github.com/lest))
|
12
|
+
|
7
13
|
## 0.10.0 (February 17, 2015) ##
|
8
14
|
|
9
15
|
### enhancements
|
data/lib/enumerize/attribute.rb
CHANGED
@@ -26,12 +26,6 @@ module Enumerize
|
|
26
26
|
@default_value = find_default_value(options[:default])
|
27
27
|
raise ArgumentError, 'invalid default value' unless @default_value
|
28
28
|
end
|
29
|
-
|
30
|
-
# Define methods to get each value
|
31
|
-
@values.each do |v|
|
32
|
-
metaclass = class << self; self; end
|
33
|
-
metaclass.send(:define_method, v.to_s) { v }
|
34
|
-
end
|
35
29
|
end
|
36
30
|
|
37
31
|
def find_default_value(value)
|
@@ -81,6 +75,10 @@ module Enumerize
|
|
81
75
|
values.map { |v| [v.text, v.to_s] }
|
82
76
|
end
|
83
77
|
|
78
|
+
def respond_to_missing?(method, include_private=false)
|
79
|
+
@value_hash.include?(method.to_s) || super
|
80
|
+
end
|
81
|
+
|
84
82
|
def define_methods!(mod)
|
85
83
|
mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
86
84
|
def #{name}
|
@@ -123,6 +121,16 @@ module Enumerize
|
|
123
121
|
end
|
124
122
|
RUBY
|
125
123
|
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def method_missing(method)
|
128
|
+
if @value_hash.include?(method.to_s)
|
129
|
+
find_value(method)
|
130
|
+
else
|
131
|
+
super
|
132
|
+
end
|
133
|
+
end
|
126
134
|
end
|
127
135
|
|
128
136
|
module Multiple
|
@@ -1,29 +1,20 @@
|
|
1
1
|
module Enumerize
|
2
2
|
module Predicatable
|
3
|
-
def method_missing(method, *args, &block)
|
4
|
-
if boolean_method?(method)
|
5
|
-
define_query_methods
|
6
|
-
send(method, *args, &block)
|
7
|
-
else
|
8
|
-
super
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
3
|
def respond_to_missing?(method, include_private=false)
|
13
|
-
|
4
|
+
predicate_method?(method) || super
|
14
5
|
end
|
15
6
|
|
16
7
|
private
|
17
8
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
9
|
+
def method_missing(method, *args, &block)
|
10
|
+
if predicate_method?(method)
|
11
|
+
predicate_call(method[0..-2], *args, &block)
|
12
|
+
else
|
13
|
+
super
|
23
14
|
end
|
24
15
|
end
|
25
16
|
|
26
|
-
def
|
17
|
+
def predicate_method?(method)
|
27
18
|
method[-1] == '?' && @attr.values.include?(method[0..-2])
|
28
19
|
end
|
29
20
|
end
|
data/lib/enumerize/set.rb
CHANGED
@@ -59,12 +59,8 @@ module Enumerize
|
|
59
59
|
|
60
60
|
private
|
61
61
|
|
62
|
-
def
|
63
|
-
|
64
|
-
def #{value}?
|
65
|
-
include?("#{value}")
|
66
|
-
end
|
67
|
-
RUBY
|
62
|
+
def predicate_call(value)
|
63
|
+
include?(value)
|
68
64
|
end
|
69
65
|
|
70
66
|
def mutate!
|
data/lib/enumerize/value.rb
CHANGED
@@ -27,12 +27,8 @@ module Enumerize
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
def
|
31
|
-
|
32
|
-
def #{value}?
|
33
|
-
#{value == self}
|
34
|
-
end
|
35
|
-
RUBY
|
30
|
+
def predicate_call(value)
|
31
|
+
value == self
|
36
32
|
end
|
37
33
|
|
38
34
|
def i18n_keys
|
data/lib/enumerize/version.rb
CHANGED
data/test/attribute_test.rb
CHANGED
@@ -87,6 +87,10 @@ describe Enumerize::Attribute do
|
|
87
87
|
|
88
88
|
it 'sets up shortcut methods for each value' do
|
89
89
|
build_attr nil, :foo, :in => {:a => 1, :b => 2}
|
90
|
+
|
91
|
+
attr.must_respond_to :a
|
92
|
+
attr.must_respond_to :b
|
93
|
+
|
90
94
|
attr.a.value.must_equal 1
|
91
95
|
attr.b.value.must_equal 2
|
92
96
|
attr.a.text.must_equal 'A'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumerize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Nartimov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
101
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
102
|
+
rubygems_version: 2.2.2
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper support
|