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

Instance Method Summary collapse

Instance Attribute Details

#entity_idInteger? (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.

Returns:

  • (Integer, nil)

    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.

Parameters:

  • symbol (Symbol)

    the potential accessor attribute

Returns:

  • (Boolean)

    whether there is a corresponding annotation



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_attributesObject



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.

Parameters:

  • a (String)

    class name, optionally qualified by the annotation module

Returns:

  • (Class, nil)

    the annotation class with the given name, or nil if no such annotation is found

Raises:

  • (NameError)

    if there is more than one annotation class for the given name



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.

Parameters:

  • mod (AnnotationModule)

    the annotation module

Returns:

  • (Symbol)

    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.

Parameters:

  • symbol (Symbol)

    the missing constant

Returns:

  • (AnnotationModule)

    the imported annotation, if successful

Raises:

  • (NameError)

    if the annotation could not be imported



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_classClass

Returns the Annotation::DEIntegration proxy class (nil for 1.1 caTissue).

Returns:



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_idInteger?

Returns this class’s entity id, if it exists, otherwise the superclass effective entity id if the superclass is an annotation class.

Returns:

  • (Integer, nil)

    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_loadedObject

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_attributesObject

Filters CaRuby::Propertied#loadable_attributes} to exclude the {.annotation_attributes since annotation lazy-loading is not supported.

See Also:



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_attributesObject



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.

Parameters:

  • classes (<Class>)

    the classes to modify



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.

Returns:

  • (<Symbol>)

    the non-annotation unfetched 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