Module: CaTissue::Metadata
- Includes:
- CaRuby::Metadata
- Defined in:
- lib/catissue/metadata.rb
Overview
Mix-in for extending a caTissue domain class with Jinx::Metadata
introspection and 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.
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_attributes ⇒ Object
-
#annotation_class_for_name(name) ⇒ Class?
The annotation class with the given name, or nil if no such annotation is found.
-
#annotation_proxy_attribute(mod) ⇒ Symbol
The corresponding annotation proxy reference attribute.
-
#const_missing(symbol) ⇒ AnnotationModule
Loads the annotations, if necessary, and tries to get the constant again.
-
#de_integration_proxy_class ⇒ Class
The Annotation::DEIntegration proxy class (nil for 1.1 caTissue).
-
#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.
-
#ensure_annotations_loaded ⇒ Object
Loads the annotations defined for this class if necessary.
-
#loadable_attributes ⇒ Object
Filters CaRuby::Propertied#loadable_attributes} to exclude the {.annotation_attributes since annotation lazy-loading is not supported.
- #printable_attributes ⇒ Object
-
#shims(*classes) ⇒ Object
Declares that the given Annotation classes will be dynamically modified.
-
#toxic_attributes ⇒ <Symbol>
Refines the
CaRuby::Propertied.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.
12 13 14 |
# File 'lib/catissue/metadata.rb', line 12 def entity_id @entity_id 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.
45 46 47 48 49 50 |
# File 'lib/catissue/metadata.rb', line 45 def annotation_attribute?(symbol) # load annotations if necessary ensure_annotations_loaded # check for the annotation attribute annotation_defined?(symbol) end |
#annotation_attributes ⇒ Object
100 101 102 103 104 105 |
# File 'lib/catissue/metadata.rb', line 100 def annotation_attributes @ann_mod_pxy_hash ||= {} @ann_attrs ||= append_ancestor_enum(@ann_mod_pxy_hash.enum_values) do |sc| sc.annotation_attributes if sc < Annotatable end end |
#annotation_class_for_name(name) ⇒ Class?
Returns the annotation class with the given name, or nil if no such annotation is found.
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/catissue/metadata.rb', line 111 def annotation_class_for_name(name) nmod = name[/^\w+/] if name.index('::') klasses = annotation_modules.map do |mod| cnm = nmod && mod.name.demodulize == (nmod) ? name[nmod.length..-1] : name mod.module_for_name(cnm) rescue nil end klasses.compact! if klasses.size > 1 then raise NameError.new("Ambiguous #{self} annotation classes for #{name}: #{klasses.to_series}") end klasses.first end |
#annotation_proxy_attribute(mod) ⇒ Symbol
Returns the corresponding annotation proxy reference attribute.
61 62 63 64 65 |
# File 'lib/catissue/metadata.rb', line 61 def annotation_proxy_attribute(mod) (@ann_mod_pxy_hash and @ann_mod_pxy_hash[mod]) or (superclass.annotation_proxy_attribute(mod) if superclass < Annotatable) or raise AnnotationError.new("#{qp} #{mod} proxy attribute not found.") end |
#const_missing(symbol) ⇒ AnnotationModule
Loads the annotations, if necessary, and tries to get the constant again.
72 73 74 75 76 77 78 79 |
# File 'lib/catissue/metadata.rb', line 72 def const_missing(symbol) if annotations_loaded? then super else ensure_annotations_loaded const_get(symbol) end end |
#de_integration_proxy_class ⇒ Class
Returns the Annotation::DEIntegration proxy class (nil for 1.1 caTissue).
24 25 26 |
# File 'lib/catissue/metadata.rb', line 24 def de_integration_proxy_class @de_integration_proxy_class or (superclass.de_integration_proxy_class if superclass < Annotatable) 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.
30 31 32 |
# File 'lib/catissue/metadata.rb', line 30 def effective_entity_id @entity_id or parent_entity_id end |
#ensure_annotations_loaded ⇒ Object
Loads the annotations defined for this class if necessary.
35 36 37 38 |
# File 'lib/catissue/metadata.rb', line 35 def ensure_annotations_loaded # referencing the annotations loads them annotation_modules end |
#loadable_attributes ⇒ Object
Filters CaRuby::Propertied#loadable_attributes} to exclude the {.annotation_attributes since annotation lazy-loading is not supported.
88 89 90 91 92 93 |
# File 'lib/catissue/metadata.rb', line 88 def loadable_attributes @antbl_ld_attrs ||= unfetched_attributes.compose do |prop| # JRuby bug - Copied the super body to avoid infinite loop. prop.java_property? and not prop.type.abstract? and not prop.transient? and not prop.type < Annotation end end |
#printable_attributes ⇒ Object
95 96 97 98 |
# File 'lib/catissue/metadata.rb', line 95 def printable_attributes # JRuby bug - Copied super body to avoid infinite loop. See const_missing. @prbl_attrs ||= java_attributes.union(annotation_attributes) end |
#shims(*classes) ⇒ Object
Declares that the given Annotation classes will be dynamically modified. This method introspects the classes, if necessary.
18 19 20 21 |
# File 'lib/catissue/metadata.rb', line 18 def shims(*classes) # Nothing to do, since all this method does is ensure that the arguments are # introspected when they are referenced. end |
#toxic_attributes ⇒ <Symbol>
Refines the CaRuby::Propertied.toxic_attributes
to exclude annotation attributes.
55 56 57 |
# File 'lib/catissue/metadata.rb', line 55 def toxic_attributes @anbl_toxic_attrs ||= unfetched_attributes.compose { |prop| not prop.type < Annotation } end |