power_enum 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/active_record/acts/enumerated.rb +13 -8
- metadata +4 -4
@@ -55,8 +55,11 @@ module ActiveRecord
|
|
55
55
|
valid_keys = [:conditions, :order, :on_lookup_failure, :name_column]
|
56
56
|
options.assert_valid_keys(*valid_keys)
|
57
57
|
|
58
|
-
valid_keys.each do |key|
|
59
|
-
|
58
|
+
valid_keys.each do |key|
|
59
|
+
class_attribute "acts_enumerated_#{key.to_s}"
|
60
|
+
if options.has_key?( key )
|
61
|
+
self.send "acts_enumerated_#{key.to_s}=", options[key]
|
62
|
+
end
|
60
63
|
end
|
61
64
|
|
62
65
|
name_column = if options.has_key?(:name_column) then
|
@@ -64,8 +67,10 @@ module ActiveRecord
|
|
64
67
|
else
|
65
68
|
:name
|
66
69
|
end
|
67
|
-
|
68
|
-
|
70
|
+
|
71
|
+
class_attribute :acts_enumerated_name_column
|
72
|
+
self.acts_enumerated_name_column = name_column
|
73
|
+
|
69
74
|
unless self.is_a? ActiveRecord::Acts::Enumerated::EnumClassMethods
|
70
75
|
extend ActiveRecord::Acts::Enumerated::EnumClassMethods
|
71
76
|
|
@@ -90,8 +95,8 @@ module ActiveRecord
|
|
90
95
|
# Returns all the enum values. Caches results after the first time this method is run.
|
91
96
|
def all
|
92
97
|
return @all if @all
|
93
|
-
conditions =
|
94
|
-
order =
|
98
|
+
conditions = self.acts_enumerated_conditions
|
99
|
+
order = self.acts_enumerated_order
|
95
100
|
@all = where(conditions).order(order).collect{|val| val.freeze}.freeze
|
96
101
|
end
|
97
102
|
|
@@ -124,7 +129,7 @@ module ActiveRecord
|
|
124
129
|
else
|
125
130
|
raise TypeError, "#{self.name}[]: argument should be a String, Symbol or Fixnum but got a: #{arg.class.name}"
|
126
131
|
end
|
127
|
-
self.send((
|
132
|
+
self.send((self.acts_enumerated_on_lookup_failure || :enforce_none), arg)
|
128
133
|
end
|
129
134
|
|
130
135
|
# Enum lookup by id
|
@@ -170,7 +175,7 @@ module ActiveRecord
|
|
170
175
|
|
171
176
|
# Returns the name of the column this enum uses as the basic underlying value.
|
172
177
|
def name_column
|
173
|
-
@name_column ||=
|
178
|
+
@name_column ||= self.acts_enumerated_name_column
|
174
179
|
end
|
175
180
|
|
176
181
|
# ---Private methods---
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: power_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 1
|
10
|
+
version: 0.6.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Trevor Squires
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2012-02-
|
21
|
+
date: 2012-02-25 00:00:00 Z
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|