lib/maintain.rb in maintain-0.2.6 vs lib/maintain.rb in maintain-0.2.8
- old
+ new
@@ -68,9 +68,18 @@
def #{attribute}
@#{attribute} ||= self.class.maintainers[:#{attribute}].value(self)
end
EOC
+ class_eval <<-EOC, __FILE__
+ class << self
+ def maintain_#{attribute}
+ @#{attribute} ||= maintainers[:#{attribute}].states.sort{|a, b| (a[1][:compare_value] || a[1][:value]) <=> (b[1][:compare_value] || b[1][:value]) }.map{|key, value| key == value[:value] ? key : [key, value[:value]]}
+ end
+ #{"alias :#{attribute} :maintain_#{attribute}" unless respond_to?(attribute)}
+ end
+ EOC
+
# Last! Not least! Save our maintainer directly on this class. We'll use it in our setters (as in above)
# and we'll also modify it instead of replacing it outright, so subclasses or mixins can extend functionality
# without replacing it.
maintainers[attribute.to_sym] = maintainer
end