Module: CaTissue::AnnotatableClass
- Defined in:
- lib/catissue/annotation/annotatable_class.rb
Overview
Mix-in for extending a caTissue domain class with annotations.
Instance Attribute Summary collapse
-
#entity_id ⇒ Integer?
readonly
The the hook class designator that is used by caTissue to persist primary annotation objects, or nil if this is not a primary annotation class.
Class Method Summary collapse
Instance Method Summary collapse
-
#annotation_attribute?(symbol) ⇒ Boolean
If there is an existing annotation whose proxy accessor is the given symbol, then return true.
- #annotation_proxy_attribute(ann_attr) ⇒ Object
-
#const_missing(symbol) ⇒ AnnotationModule
Loads the annotations, if necessary, and tries to get the constant again.
-
#create_annotation_attribute(mod, attribute) ⇒ Object
Makes a new attribute in this hook class for the given annotation proxy domain attribute.
-
#effective_entity_id ⇒ Integer?
This class’s entity id, if it exists, otherwise the superclass effective entity id if the superclass is an annotation class.
-
#toxic_attributes ⇒ <Symbol>
Refines the CaRuby::ResourceAttributes#toxic_attributes to exclude annotation attributes.
Instance Attribute Details
#entity_id ⇒ Integer? (readonly)
Returns the the hook class designator that is used by caTissue to persist primary annotation objects, or nil if this is not a primary annotation class.
11 12 13 |
# File 'lib/catissue/annotation/annotatable_class.rb', line 11 def entity_id @entity_id end |
Class Method Details
.extended(klass) ⇒ Object
13 14 15 16 17 |
# File 'lib/catissue/annotation/annotatable_class.rb', line 13 def self.extended(klass) super # the annotation name => spec hash klass.class_eval { extend Forwardable; @ann_spec_hash = {} } end |
Instance Method Details
#annotation_attribute?(symbol) ⇒ Boolean
If there is an existing annotation whose proxy accessor is the given symbol, then return true. Otherwise, attempt to import an annotation and return whether the import was successful.
31 32 33 34 35 36 |
# File 'lib/catissue/annotation/annotatable_class.rb', line 31 def annotation_attribute?(symbol) # load annotations if necessary ensure_annotations_loaded # check for the annotation attribute annotation_defined?(symbol) end |
#annotation_proxy_attribute(ann_attr) ⇒ Object
45 46 47 |
# File 'lib/catissue/annotation/annotatable_class.rb', line 45 def annotation_proxy_attribute(ann_attr) annotatable_class_hierarchy.detect_value { |klass| klass.local_annotation_proxy_attribute(ann_attr) } end |
#const_missing(symbol) ⇒ AnnotationModule
Loads the annotations, if necessary, and tries to get the constant again.
73 74 75 76 77 78 79 80 |
# File 'lib/catissue/annotation/annotatable_class.rb', line 73 def const_missing(symbol) if annotations_loaded? then super else ensure_annotations_loaded const_get(symbol) end end |
#create_annotation_attribute(mod, attribute) ⇒ Object
Makes a new attribute in this hook class for the given annotation proxy domain attribute. The hook annotation reference attribute delegates to the proxy. This method is intended for the exclusive use of CaTissue::Annotation::ProxyClass.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/catissue/annotation/annotatable_class.rb', line 55 def create_annotation_attribute(mod, attribute) pxy = mod.proxy pxy_attr = @ann_mod_pxy_hash[mod] ann_attr_md = pxy.(attribute) # the type referenced by the annotation proxy klass = ann_attr_md.type # create annotation accessors which delegate to the proxy def_delegators(pxy_attr, *ann_attr_md.accessors) logger.debug { "Created #{qp}.#{attribute} which delegates to the annotation proxy #{pxy_attr}." } # add the attribute add_annotation_attribute(attribute, klass) end |
#effective_entity_id ⇒ Integer?
Returns this class’s entity id, if it exists, otherwise the superclass effective entity id if the superclass is an annotation class.
21 22 23 |
# File 'lib/catissue/annotation/annotatable_class.rb', line 21 def effective_entity_id @entity_id or parent_entity_id end |
#toxic_attributes ⇒ <Symbol>
Refines the CaRuby::ResourceAttributes#toxic_attributes to exclude annotation attributes.
41 42 43 |
# File 'lib/catissue/annotation/annotatable_class.rb', line 41 def toxic_attributes @anntbl_toxic_attrs ||= unfetched_attributes.compose { |attr_md| not attr_md.type < Annotation } end |