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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 964f689869d7570459451bae1068a737f69a7db2
4
- data.tar.gz: b1c59894d98bd2656d01c5bca52f4dc15a7fa42a
3
+ metadata.gz: 7430100f0e35ac39085f08ca0dca223b4f101a86
4
+ data.tar.gz: 5726bf780a70d9cfd67e6c51622c734abd7a9644
5
5
  SHA512:
6
- metadata.gz: 61ca5ff5fcaac6dd6a38622fbf2af35f74896bf57f9f317cbc2b7b918814ab9b4aa5e9a6437de14b709a72b61d2d09c04c7d86a6504335faed7fd008c21b2051
7
- data.tar.gz: 8a5e9bb95f72b0abbdd5619ace2299ed8d3001d520d747751d00a84d474ecdfb82a3fce065c6af3d9e422fe1d38cdf288e286d578a95fda836b0f02606ee4c21
6
+ metadata.gz: 1221db4e0a2377d4123c0d64f3b0fbcf63d549e15963d44562a96d4a68eac0017015fbba7ce4e56bdaf4f6904ca5ab99592fdad70813333cdd52032ae440902c
7
+ data.tar.gz: dfd016c59f61900a641483df577bf793ce9f6b36f695958d6f9676ef49ed4f54d7cce57e1a2c9936ab8f7f63ee76f9932244d998474cf32677a55671339cc6d8
data/.travis.yml CHANGED
@@ -9,8 +9,13 @@ gemfile:
9
9
  rvm:
10
10
  - 1.9.3
11
11
  - 2.0.0
12
- - 2.1.0
12
+ - 2.1
13
+ - 2.2
13
14
  - jruby-19mode
15
+ matrix:
16
+ exclude:
17
+ - rvm: 2.2
18
+ gemfile: Gemfile
14
19
  notifications:
15
20
  email:
16
21
  recipients:
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
@@ -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
- boolean_method?(method)
4
+ predicate_method?(method) || super
14
5
  end
15
6
 
16
7
  private
17
8
 
18
- def define_query_methods
19
- @attr.values.each do |value|
20
- unless singleton_methods.include?(:"#{value}?")
21
- define_query_method(value)
22
- end
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 boolean_method?(method)
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 define_query_method(value)
63
- singleton_class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
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!
@@ -27,12 +27,8 @@ module Enumerize
27
27
 
28
28
  private
29
29
 
30
- def define_query_method(value)
31
- singleton_class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
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
@@ -1,3 +1,3 @@
1
1
  module Enumerize
2
- VERSION = "0.10.0"
2
+ VERSION = "0.10.1"
3
3
  end
@@ -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.0
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-02-17 00:00:00.000000000 Z
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.4.5
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