enum_field 1.0.0 → 1.0.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/README.rdoc +1 -1
- data/lib/enum_field/enumerated_attribute.rb +4 -6
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -80,7 +80,7 @@ You have some +AR+ like methods in enum classes
|
|
80
80
|
PhoneType.find(2) == PhoneType.commercial
|
81
81
|
PhoneType.find(123456) # will raise
|
82
82
|
|
83
|
-
|
83
|
+
The library also mimics has_many :through behavior, for cases such as:
|
84
84
|
|
85
85
|
class Role
|
86
86
|
define_enum do |builder|
|
@@ -49,14 +49,15 @@ module EnumeratedAttribute
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
# alias of enumerated_attribute
|
52
53
|
alias belongs_to_enumerated_attribute enumerated_attribute
|
53
54
|
|
54
|
-
#
|
55
|
+
# Defines a one-to-many association between an AR class and the enumerated
|
55
56
|
# * +association+: the name of the one-to-many association, for instance +roles+
|
56
57
|
# * +options+: Valid options are:
|
57
58
|
# * +through+ : the name of the AR class needed to persist the one-to-many association.
|
58
|
-
# Defaults to AR class in camelcase form
|
59
|
-
# * +class+: the enumerated class
|
59
|
+
# Defaults to AR class in camelcase form concatenated with the enumerated class in camelcase form.
|
60
|
+
# * +class+: the enumerated class, it will be instantiated +n+ times when +association+ method is called.
|
60
61
|
# Defaults to +association+ in singular camelcase form.
|
61
62
|
def has_many_enumerated_attributes(association, options = {})
|
62
63
|
enum_attr = association.to_s.singularize
|
@@ -83,9 +84,6 @@ module EnumeratedAttribute
|
|
83
84
|
define_method(association_ids + '=') do |values|
|
84
85
|
self.send(has_many_aux + '=', values.map{|g| g.to_i unless g.blank?}.compact.map{|g_id| through.constantize.new(self_attribute => self, enum_attr + '_id' => g_id) })
|
85
86
|
end
|
86
|
-
|
87
87
|
end
|
88
|
-
|
89
88
|
end
|
90
|
-
|
91
89
|
end
|