In my attempt to add AM:Dirty to my model I realized that
AM#AttributeMethods is a bit imperfect. It's impossible to generate
attribute methods step-by-step in DataMapper-like manner.
class Model
include ActiveModel::Dirty
def self.property(name, klass = String)
define_property_accessors(name, klass)
# This method will be called once, because of
https://github.com/rails/rails/blob/master/activemodel/lib/active_model/attribute_methods.rb#L263
define_attribute_methods([name])
end
end
class Article < Model
property :title
property :body
property :published_at, Time
end
In the above example, attribute methods will be defined just
for :title. I don't see any nice workaround.
So what is the purpose of
AttributeMethods#attribute_methods_generated? I can't imagine any use
case for this. What about removing it entirely and providing
#define_attribute_method(s) with ability to call it multiple times? Am
I missing something?