Module: CaTissue::Annotatable
Overview
Annotatable extends Resource with annotation capability.
Instance Method Summary collapse
- #method_missing(mth, *args) ⇒ Object
-
#proxy_for(attribute, annotation) ⇒ Proxy
The hook proxy for the given annotation.
Methods included from Resource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mth, *args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/catissue/annotation/annotatable.rb', line 8 def method_missing(mth, *args) name = mth.to_s # remove trailing assignment '=' character if present pa = name =~ /=$/ ? name.chop.to_sym : mth # If an annotation can be generated on demand, then resend the method. # Otherwise, delegate to super for the standard error. begin self.class.annotation_attribute?(pa) ? send(mth, *args) : super rescue AnnotationError => e raise e rescue NoMethodError super end end |
Instance Method Details
#proxy_for(attribute, annotation) ⇒ Proxy
Returns the hook proxy for the given annotation.
26 27 28 29 30 31 32 33 34 |
# File 'lib/catissue/annotation/annotatable.rb', line 26 def proxy_for(attribute, annotation) @ann_pxy_hash ||= Jinx::LazyHash.new do |ann| pxy = self.class.property(attribute).type.new pxy.hook = self send(attribute) << pxy pxy end @ann_pxy_hash[annotation] end |