Module: Persistence::Object::Complex::ClassAndObjectInstance

Includes:
CascadingConfiguration::Hash
Included in:
ClassInstance, ObjectInstance
Defined in:
lib/persistence/object/complex/class_and_object_instance.rb

Overview

Methods applied to both Class and Object instances of complex objects enabled with persistence capabilities.

Instance Method Summary collapse

Instance Method Details

#attr_delete_cascades(attribute_name, ...) ⇒ Object

Declare that deleting object should also delete attribute(s).

Parameters:

  • attribute_name

    Attribute(s) in question.

Returns:

  • self


32
33
34
35
36
37
38
39
40
# File 'lib/persistence/object/complex/class_and_object_instance.rb', line 32

def attr_delete_cascades( *attributes )
  
  attributes.each do |this_attribute|
    delete_cascades[ this_attribute.accessor_name ] = true
  end
  
  return self
  
end

#attr_delete_cascades!Object

Declare that deleting object should also delete declared attributes.

Returns:

  • self


74
75
76
77
78
# File 'lib/persistence/object/complex/class_and_object_instance.rb', line 74

def attr_delete_cascades!

  return attr_delete_cascades( *persistent_attributes.keys )

end

#attr_delete_cascades(attribute_name, ...) ⇒ Object

Declare that deleting object should not delete attribute(s).

Parameters:

  • attribute_name

    Attribute(s) in question.

Returns:

  • self


55
56
57
58
59
60
61
62
63
# File 'lib/persistence/object/complex/class_and_object_instance.rb', line 55

def attr_delete_does_not_cascade( *attributes )
  
  attributes.each do |this_attribute|
    delete_cascades[ this_attribute.accessor_name ] = false
  end
  
  return self
  
end

#attr_delete_does_not_cascade!Object

Declare that deleting object should not delete declared attributes.

Returns:

  • self


90
91
92
93
94
# File 'lib/persistence/object/complex/class_and_object_instance.rb', line 90

def attr_delete_does_not_cascade!

  return attr_delete_does_not_cascade( *persistent_attributes.keys )

end

#delete_cascadesCompositingHash{Symbol,String=>true,false}

Returns Hash containing cascading delete data for attributes.

Returns:

  • (CompositingHash{Symbol,String=>true,false})

    Hash containing cascading delete data for attributes.


21
# File 'lib/persistence/object/complex/class_and_object_instance.rb', line 21

attr_configuration_hash :delete_cascades

#delete_cascades?(attribute_name) ⇒ true, false

Query whether deleting object will also delete attribute

Parameters:

  • attribute_name

    Attribute in question.

Returns:

  • (true, false)

    Whether deleting object will cascade to delete object at attribute.


107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/persistence/object/complex/class_and_object_instance.rb', line 107

def delete_cascades?( attribute_name )

  should_cascade = false

  accessor_name = attribute_name.accessor_name

  # delete_cascades is a cascading array that automatically handles inheritance
  if ( should_cascade = delete_cascades[ accessor_name ] ) == nil

    if attribute_value = persistence_port.get_attribute( self, accessor_name ) and
       attribute_value.is_a?( ::Persistence::Object::Complex::ComplexObject )

      should_cascade = attribute_value.delete_cascades?

    end

    should_cascade = true if should_cascade.nil?
    delete_cascades[ accessor_name ] = should_cascade

  end

  return should_cascade

end