Module: CaTissue::Annotation::ProxyClass

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

Overview

Annotation hook proxy class mix-in.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hookAnnotatableClass (readonly)

Returns the hook class for this proxy.

Returns:



10
11
12
# File 'lib/catissue/annotation/proxy_class.rb', line 10

def hook
  @hook
end

Class Method Details

.extended(klass) ⇒ Object

Parameters:

  • klass (Class)

    the proxy class



13
14
15
16
# File 'lib/catissue/annotation/proxy_class.rb', line 13

def self.extended(klass)
  super
  klass.class_eval { include Proxy }
end

Instance Method Details

#add_annotation_dependentsObject

Adds each proxy => annotation reference as a dependent attribute.



39
40
41
42
43
44
45
46
47
# File 'lib/catissue/annotation/proxy_class.rb', line 39

def add_annotation_dependents
  annotation_attributes. do |attr_md|
    attr_md.type.add_dependent_attributes
    attr_md.type.proxy = self
  end
  annotation_attributes. do |attr_md|
    attr_md.type.add_dependent_attribute_closure
  end
end

#annotation_attributesObject



18
19
20
# File 'lib/catissue/annotation/proxy_class.rb', line 18

def annotation_attributes
  @ann_attrs ||= domain_attributes.compose { |attr_md| attr_md.type < Annotation }
end

#create_annotation_attribute(klass, inverse) ⇒ Object

Creates a reference attribute from this proxy to the given primary CaTissue::Annotation class.

Parameters:

  • klass (Class)

    the annotation class

  • inverse (Symbol)

    the annotation => proxy attribute



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/catissue/annotation/proxy_class.rb', line 53

def create_annotation_attribute(klass, inverse)
  # the new attribute symbol
  attr = klass.name.demodulize.underscore.pluralize.to_sym
  logger.debug { "Creating annotation proxy #{qp} attribute #{attr} 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(attr) { Set.new }
  # add the annotation collection attribute
  add_attribute(attr, klass, :collection)
  # make the hook attribute which delegates to this proxy
  @hook.create_annotation_attribute(domain_module, attr)
  # set the attribute inverse
  set_attribute_inverse(attr, inverse)
end

#set_hook(klass, inverse) ⇒ Object

Sets this proxy’s hook to the given class. Creates the proxy => hook attribute with the given hook => proxy inverse.

Parameters:

  • klass (Class)

    the hook class

  • inverse (Symbol)

    the hook class hook => proxy attribute



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

def set_hook(klass, inverse)
  @hook = klass
  # Make a new hook reference attribute.
  attr_accessor(:hook)
  # The attribute type is the given hook class.
  add_attribute(:hook, klass)
  # Setting one end of the hook <-> proxy association sets the other end.
  set_attribute_inverse(:hook, inverse)
  logger.debug { "Added #{klass.qp} annotation proxy => hook attribute with inverse #{klass.qp}.#{inverse}." }
end