Introduce an interface for registering custom attribute extensions
As discussed in #207
Virtus::Attribute.register_extension(Virtus::Attribute::Annotated)
# it requires some method that would tell virtus when to use it
# maybe something like this:
module Virtus::Attribute::Annotated
def self.extend?(options)
options.key?(:annotations)
end
def annotations
options[:annotations]
end
end
# then in the Builder#initialize_attribute we could simply extend attribute
# with all registered extensions
Attribute.extensions.each do |mod|
@attribute.extend(mod) if mod.extend?(@attribute.options)
end
IMPORTANT: this won't block 1.0.0 though, can be added in 1.x as it's just a new feature. Details have not been defined yet.
It may be better to use attribute as argument for extend? method, because extension may want to access not only options, but i.e. name, to decide to be applied or not.
That's a great suggestion
On Thu, Oct 3, 2013 at 3:55 PM, mirasrael [email protected] wrote:
It may be better to use
attributeas argument forextend?method, because extension may want to access not only options, but i.e. name, to decide to be applied or not.Reply to this email directly or view it on GitHub: https://github.com/solnic/virtus/issues/208#issuecomment-25622146
Are you working on this feature or I can suggest it as pull request?
No I'm not planning to work on it anytime soon. Would love to see a PR :)
On Thu, Oct 3, 2013 at 4:04 PM, mirasrael [email protected] wrote:
Are you working on this future or I can suggest it as pull request?
Reply to this email directly or view it on GitHub: https://github.com/solnic/virtus/issues/208#issuecomment-25622883
I opened pull request #209
@mirasrael thanks! that was fast :) I left some comments