Fix conflict between normalize and array_attribute macros.
Fix the `normalize` and `array_attribute` macros conflicting with each other on the WikiPage model. This meant code like `wiki_page.other_names = "foo bar"` didn't work. Both macros defined a `other_names=` method, but one method overrode the other. The fix is to use anonymous modules and prepend so we can chain method calls with super.
This commit is contained in:
@@ -3,10 +3,14 @@ module Normalizable
|
||||
|
||||
class_methods do
|
||||
def normalize(attribute, method_name)
|
||||
define_method("#{attribute}=") do |value|
|
||||
normalized_value = self.class.send(method_name, value)
|
||||
super(normalized_value)
|
||||
mod = Module.new do
|
||||
define_method("#{attribute}=") do |value|
|
||||
normalized_value = self.class.send(method_name, value)
|
||||
super(normalized_value)
|
||||
end
|
||||
end
|
||||
|
||||
prepend mod
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user