Module: CaTissue::AnnotationClass

Defined in:
lib/catissue/annotation/annotation_class.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#container_idIntger? (readonly)

Returns the container id, or nil if this is not a primary annotation.

Returns:

  • (Intger, nil)

    the container id, or nil if this is not a primary annotation



15
16
17
# File 'lib/catissue/annotation/annotation_class.rb', line 15

def container_id
  @container_id
end

#entity_idInteger? (readonly)

Returns the annotation class designator that is used by caTissue to persist primary annotation objects, or nil if this is not a primary annotation.

Returns:

  • (Integer, nil)

    the annotation class designator that is used by caTissue to persist primary annotation objects, or nil if this is not a primary annotation



12
13
14
# File 'lib/catissue/annotation/annotation_class.rb', line 12

def entity_id
  @entity_id
end

#proxy_attributeSymbol? (readonly)

Returns the annotation => proxy attribute, or nil if this is not a primary annotation.

Returns:

  • (Symbol, nil)

    the annotation => proxy attribute, or nil if this is not a primary annotation



8
9
10
# File 'lib/catissue/annotation/annotation_class.rb', line 8

def proxy_attribute
  @proxy_attribute
end

Class Method Details

.extended(klass) ⇒ Object

Infers the given annotation class dependent attributes as described in #infer_dependents.

Parameters:

  • klass (Class)

    the annotation class



21
22
23
24
# File 'lib/catissue/annotation/annotation_class.rb', line 21

def self.extended(klass)
  super
  klass.extend_as_annotation
end

Instance Method Details

#ensure_primary_has_proxy(proxy) ⇒ Object

Creates the proxy attribute if this is a primary_entity annotation class which does not have a caTissue proxy property.

Parameters:

  • proxy (Class)

    the AnnotationProxy class



41
42
43
# File 'lib/catissue/annotation/annotation_class.rb', line 41

def ensure_primary_has_proxy(proxy)
  if primary? then @proxy_attribute ||= create_proxy_attribute(proxy) end
end

#extend_as_annotationObject

Adds metadata to this annotation class.



27
28
29
30
31
32
33
34
35
# File 'lib/catissue/annotation/annotation_class.rb', line 27

def extend_as_annotation
  efcd = Annotation::EntityFacade.instance
  # The entity id, or nil if this is not a primary entity.
  @entity_id = efcd.primary_entity_id(self, false)
  # A primary entity has a container id.
  if @entity_id then @container_id = efcd.container_id(@entity_id) end
  # infer non-dependent attribute inverses
  detect_inverses
end

#hook=(klass) ⇒ Object

Parameters:

  • klass (Class)

    the hook class for this primary annotation



69
70
71
72
73
74
75
76
# File 'lib/catissue/annotation/annotation_class.rb', line 69

def hook=(klass)
  # only a primary can have a hook
  unless primary? then
    raise AnnotationError.new("#{domain_module.qp} annotation #{qp} #{domain_module.proxy.qp} proxy owner accessor attribute not found.")
  end
  # redirect the hook writer method to write to the proxy instead
  convert_hook_to_proxy(klass)
end

#hook_proxy_attributeSymbol?

Returns the hook proxy class attribute which references this annotation, or nil if this class is not a primary annotation class.

Returns:

  • (Symbol, nil)

    the hook proxy class attribute which references this annotation, or nil if this class is not a primary annotation class



80
81
82
83
# File 'lib/catissue/annotation/annotation_class.rb', line 80

def hook_proxy_attribute
  # The hook => primary attribute symbol is the same as the proxy => primary attribute symbol.
  (@proxy_attribute).inverse if @proxy_attribute
end

#primary?Boolean

Returns whether this annotation class references a hook proxy.

Returns:

  • (Boolean)

    whether this annotation class references a hook proxy



93
94
95
# File 'lib/catissue/annotation/annotation_class.rb', line 93

def primary?
  not @entity_id.nil?
end

#primary_owner_attributesSymbol?

Returns the primary owner annotation, if it exists.

Returns:

  • (Symbol, nil)

    the primary owner annotation, if it exists



86
87
88
89
90
# File 'lib/catissue/annotation/annotation_class.rb', line 86

def primary_owner_attributes
  @pr_owr_attrs ||= domain_attributes.compose do |attr_md|
    attr_md.type < Annotation and attr_md.type.method_defined?(:hook)
  end
end

#proxy=(proxy) ⇒ Object

Detects or creates the proxy attribute that references the given proxy class. if this is a primary_entity annotation class which does not have a caTissue proxy property.

Parameters:

  • proxy (Class)

    the AnnotationProxy class



57
58
59
60
61
62
63
64
65
66
# File 'lib/catissue/annotation/annotation_class.rb', line 57

def proxy=(proxy)
  # msut be primary
  unless primary? then raise AnnotationError.new("Can't set proxy for non-primary annotation class #{qp}") end
  # make the proxy attribute
  @proxy_attribute = obtain_proxy_attribute(proxy)
  # set the hook
  self.hook = proxy.hook
  # primary superclass gets a proxy as well
  if superclass < Annotation and superclass.primary? then superclass.proxy = proxy end
end

#save_dependent_attributes(annotation) ⇒ Object

Saves the annotations referenced by the given annotation.

Parameters:

  • annotation (Annotation)

    the subject annotation



48
49
50
# File 'lib/catissue/annotation/annotation_class.rb', line 48

def save_dependent_attributes(annotation)
  dependent_attributes.each { |attr| save_dependent_attribute(annotation, attr) }
end

#toxic_attributesArray

Returns an empty array, since no annotation reference is lazy-loaded by caTissue.

Returns:

  • (Array)

    an empty array, since no annotation reference is lazy-loaded by caTissue.



98
99
100
# File 'lib/catissue/annotation/annotation_class.rb', line 98

def toxic_attributes
  Array::EMPTY_ARRAY
end