active_enum 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/active_enum/extensions.rb +8 -4
- data/lib/active_enum/version.rb +1 -1
- data/spec/spec_helper.rb +2 -1
- metadata +12 -5
@@ -26,8 +26,6 @@ module ActiveEnum
|
|
26
26
|
# enumerate :to, :from, :with => Sex
|
27
27
|
#
|
28
28
|
def enumerate(*attributes, &block)
|
29
|
-
define_attribute_methods unless generated_methods?
|
30
|
-
|
31
29
|
options = attributes.extract_options!
|
32
30
|
attributes.each do |attribute|
|
33
31
|
begin
|
@@ -64,6 +62,8 @@ module ActiveEnum
|
|
64
62
|
# user.sex(:enum)
|
65
63
|
#
|
66
64
|
def define_active_enum_read_method(attribute)
|
65
|
+
define_read_method(attribute, attribute.to_s, columns_hash[attribute.to_s]) unless instance_method_already_implemented?(attribute.to_s)
|
66
|
+
|
67
67
|
old_method = "#{attribute}_without_enum"
|
68
68
|
define_method("#{attribute}_with_enum") do |*arg|
|
69
69
|
arg = arg.first
|
@@ -91,6 +91,8 @@ module ActiveEnum
|
|
91
91
|
# user.sex = :male
|
92
92
|
#
|
93
93
|
def define_active_enum_write_method(attribute)
|
94
|
+
define_write_method(attribute) unless instance_method_already_implemented?("#{attribute}=")
|
95
|
+
|
94
96
|
old_method = "#{attribute}_without_enum="
|
95
97
|
define_method("#{attribute}_with_enum=") do |arg|
|
96
98
|
enum = self.class.enum_for(attribute)
|
@@ -102,7 +104,7 @@ module ActiveEnum
|
|
102
104
|
end
|
103
105
|
end
|
104
106
|
|
105
|
-
alias_method_chain "#{attribute}="
|
107
|
+
alias_method_chain :"#{attribute}=", :enum
|
106
108
|
end
|
107
109
|
|
108
110
|
# Define question method to check enum value against attribute value
|
@@ -110,6 +112,8 @@ module ActiveEnum
|
|
110
112
|
# user.sex?(:male)
|
111
113
|
#
|
112
114
|
def define_active_enum_question_method(attribute)
|
115
|
+
define_question_method(attribute) unless instance_method_already_implemented?("#{attribute}?")
|
116
|
+
|
113
117
|
old_method = "#{attribute}_without_enum?"
|
114
118
|
define_method("#{attribute}_with_enum?") do |*arg|
|
115
119
|
arg = arg.first
|
@@ -119,7 +123,7 @@ module ActiveEnum
|
|
119
123
|
send(old_method)
|
120
124
|
end
|
121
125
|
end
|
122
|
-
alias_method_chain "#{attribute}?"
|
126
|
+
alias_method_chain :"#{attribute}?", :enum
|
123
127
|
end
|
124
128
|
|
125
129
|
end
|
data/lib/active_enum/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -20,9 +20,10 @@ module SpecHelper
|
|
20
20
|
def reset_class(klass, &block)
|
21
21
|
name = klass.name.to_sym
|
22
22
|
Object.send(:remove_const, name)
|
23
|
-
|
23
|
+
eval "class #{klass}#{' < ' + klass.superclass.to_s if klass.superclass != Class}; end", TOPLEVEL_BINDING
|
24
24
|
new_klass = Object.const_get(name)
|
25
25
|
new_klass.class_eval &block if block_given?
|
26
|
+
new_klass
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 6
|
8
|
+
- 4
|
9
|
+
version: 0.6.4
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Adam Meehan
|
@@ -9,7 +14,7 @@ autorequire: active_enum
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-04-26 00:00:00 +10:00
|
13
18
|
default_executable:
|
14
19
|
dependencies: []
|
15
20
|
|
@@ -51,18 +56,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
51
56
|
requirements:
|
52
57
|
- - ">="
|
53
58
|
- !ruby/object:Gem::Version
|
59
|
+
segments:
|
60
|
+
- 0
|
54
61
|
version: "0"
|
55
|
-
version:
|
56
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
63
|
requirements:
|
58
64
|
- - ">="
|
59
65
|
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 0
|
60
68
|
version: "0"
|
61
|
-
version:
|
62
69
|
requirements: []
|
63
70
|
|
64
71
|
rubyforge_project: active_enum
|
65
|
-
rubygems_version: 1.3.
|
72
|
+
rubygems_version: 1.3.6
|
66
73
|
signing_key:
|
67
74
|
specification_version: 3
|
68
75
|
summary: Define enum classes in Rails and use them to enumerate ActiveRecord attributes
|