Module: CaTissue::Annotation::ProxyClass
- Defined in:
- lib/catissue/annotation/proxy_class.rb
Overview
Annotation hook proxy class mix-in.
Instance Attribute Summary collapse
-
#hook_property ⇒ CaRuby::Property
readonly
The hook class attribute meta-data for this proxy.
Class Method Summary collapse
Instance Method Summary collapse
-
#build_annotation_dependency_hierarchy ⇒ Object
Adds each proxy => annotation reference as a dependent attribute.
-
#create_annotation_attribute(klass) ⇒ Symbol
Creates a reference attribute from this proxy to the given primary CaTissue::Annotation class.
-
#ensure_primary_references_proxy(klass) ⇒ Object
Ensures that the given primary class references this proxy.
-
#hook ⇒ Metadata
The hook class for this proxy.
-
#hook=(klass) ⇒ Object
Sets this proxy’s hook to the given class and creates the proxy => hook attribute with the given hook => proxy inverse.
Instance Attribute Details
#hook_property ⇒ CaRuby::Property (readonly)
Returns the hook class attribute meta-data for this proxy.
14 15 16 |
# File 'lib/catissue/annotation/proxy_class.rb', line 14 def hook_property @hook_property end |
Class Method Details
.extended(klass) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/catissue/annotation/proxy_class.rb', line 17 def self.extended(klass) super # distinguish the 1.1 from the 1.2 proxy class mixin = klass.name =~ /RecordEntry$/ ? RecordEntryProxy : Proxy_1_1 klass.class_eval { include mixin } end |
Instance Method Details
#build_annotation_dependency_hierarchy ⇒ Object
Adds each proxy => annotation reference as a dependent attribute. Recursively adds dependents of all referenced annotations.
This method defines a proxy attribute in each primary annotation class for each #non_proxy_annotation_classes class hierarchy.
47 48 49 50 51 52 53 54 55 |
# File 'lib/catissue/annotation/proxy_class.rb', line 47 def build_annotation_dependency_hierarchy logger.debug { "Building the #{annotation_module.qp} annotation proxy #{self} dependency hierarchy..." } non_proxy_annotation_classes.each do |klass| ensure_primary_references_proxy(klass) end set_inverses add_dependent_attributes add_dependent_attribute_closure end |
#create_annotation_attribute(klass) ⇒ Symbol
Creates a reference attribute from this proxy to the given primary CaTissue::Annotation class.
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/catissue/annotation/proxy_class.rb', line 73 def create_annotation_attribute(klass) # the new attribute symbol pa = klass.name.demodulize.underscore.pluralize.to_sym logger.debug { "Creating annotation proxy #{qp} attribute #{pa} to hold primary annotation #{klass.qp} instances..." } # Define the access methods: the reader creates a new set on demand to hold the annotations. attr_create_on_demand_accessor(pa) { Set.new } # add the annotation collection attribute add_attribute(pa, klass, :collection) # The annotation is dependent. add_dependent_attribute(pa, :logical) logger.debug { "Created annotation proxy #{qp} dependent attribute #{pa}." } pa end |
#ensure_primary_references_proxy(klass) ⇒ Object
Ensures that the given primary class references this proxy.
60 61 62 63 64 65 66 67 |
# File 'lib/catissue/annotation/proxy_class.rb', line 60 def ensure_primary_references_proxy(klass) # Define the superclass proxy attributes, starting with the most general class. klass.annotation_hierarchy.to_a.reverse_each do |anc| if anc.primary? and anc.proxy_attribute.nil? then anc.define_proxy_attribute(self) end end end |
#hook ⇒ Metadata
Returns the hook class for this proxy.
25 26 27 |
# File 'lib/catissue/annotation/proxy_class.rb', line 25 def hook hook_property.type end |
#hook=(klass) ⇒ Object
Sets this proxy’s hook to the given class and creates the proxy => hook attribute with the given hook => proxy inverse.
33 34 35 36 37 38 39 40 |
# File 'lib/catissue/annotation/proxy_class.rb', line 33 def hook=(klass) # Make a new hook reference attribute. pa = klass.name.demodulize.underscore attr_accessor(pa) # The attribute type is the given hook class. @hook_property = add_attribute(pa, klass) logger.debug { "Added #{klass.qp} annotation proxy => hook attribute #{pa}." } end |