Module: Persistence::Object::Complex::ClassInstance

Includes:
CascadingConfiguration::Array::Unique, Attributes, ClassAndObjectInstance
Included in:
Persistence::Object::Complex
Defined in:
lib/persistence/object/complex/class_instance.rb

Overview

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

Instance Method Summary collapse

Methods included from ClassAndObjectInstance

#attr_delete_cascades, #attr_delete_cascades!, #attr_delete_does_not_cascade, #attr_delete_does_not_cascade!, #delete_cascades, #delete_cascades?

Methods included from Attributes

#atomic_attribute?, #atomic_attribute_accessor?, #atomic_attribute_accessors, #atomic_attribute_reader?, #atomic_attribute_readers, #atomic_attribute_status, #atomic_attribute_writer?, #atomic_attribute_writers, #atomic_attributes, #attr_atomic_accessor, #attr_atomic_reader, #attr_atomic_writer, #attr_non_atomic_accessor, #attr_non_atomic_reader, #attr_non_atomic_writer, #attrs_atomic!, #attrs_non_atomic!, #non_atomic_attribute?, #non_atomic_attribute_accessor?, #non_atomic_attribute_accessors, #non_atomic_attribute_reader?, #non_atomic_attribute_readers, #non_atomic_attribute_status, #non_atomic_attribute_writer?, #non_atomic_attribute_writers, #non_atomic_attributes, #persistent_attribute?, #persistent_attribute_accessor?, #persistent_attribute_accessors, #persistent_attribute_reader?, #persistent_attribute_readers, #persistent_attribute_status, #persistent_attribute_writer?, #persistent_attribute_writers, #persistent_attributes

Instance Method Details

#attr_flat(attribute_name, ...) ⇒ Object

Declare that an attribute should be treated as a flat object by persistence port, regardless whether it

actually is a flat object.

Parameters:

  • attribute_name

    Name of attribute to treat as flat object.

Returns:

  • self



194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/persistence/object/complex/class_instance.rb', line 194

def attr_flat( *attributes )

  if attributes.empty?
    persists_flat[ nil ] = true
  else
    attributes.each do |this_attribute|
      persists_flat.push( this_attribute )
    end
  end
  
  return self
  
end

#attr_flat!Object

Declare Persistence::Object::Complex::ClassInstance.selfself#attr_flat on all attributes.

Returns:

  • self



217
218
219
220
221
222
223
# File 'lib/persistence/object/complex/class_instance.rb', line 217

def attr_flat!
  
  attr_flat( *persistent_attribute_writers )

  return self
  
end

#attr_index(attribute_name, ...) ⇒ Object

Declare an index on attribute(s).

Parameters:

  • attribute_name

    Name of object property to index. Creates accessor if method by name does not already exist.

Returns:

  • self



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/persistence/object/complex/class_instance.rb', line 27

def attr_index( *attributes )

 parent_bucket = instance_persistence_bucket

 attributes.each do |this_attribute|
   index_instance = ::Persistence::Object::Complex::Index::AttributeIndex.new( this_attribute, parent_bucket, false )
   index_instance.attribute_name = this_attribute
   indexes[ this_attribute ] = attribute_indexes[ this_attribute ] = index_instance
 end

 return self

end

#attr_index(attribute_name, ...) ⇒ Object

Declare an ordered index on attribute(s). PENDING.

Parameters:

  • attribute_name

    Name of object property to index. Creates accessor if method by name does not already exist.

Returns:

  • self



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/persistence/object/complex/class_instance.rb', line 55

def attr_index_ordered( attributes, & ordering_block )
 
 raise 'pending'
 
 parent_bucket = instance_persistence_bucket

 attributes.each do |this_attribute|
   index_instance = ::Persistence::Object::Complex::Index::AttributeIndex.new( this_attribute, 
                                                                               parent_bucket,
                                                                               true,
                                                                               ordering_block )
   index_instance.attribute_name = this_attribute
   indexes[ this_attribute ] = attribute_indexes[ this_attribute ] = index_instance
 end

 return self

end

#attr_index_ordered_with_duplicates(attribute_name, ...) ⇒ Object

Declare an ordered index permitting duplicates on attribute(s). PENDING.

Parameters:

  • attribute_name

    Name of object property to index. Creates accessor if method by name does not already exist.

Returns:

  • self



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/persistence/object/complex/class_instance.rb', line 114

def attr_index_ordered_with_duplicates( attribute, duplicates_ordering_proc = nil, & ordering_block )

  raise 'pending'

  index_instance = ::Persistence::Object::Complex::Index::AttributeIndex.new( attribute, 
                                                                              parent_bucket,
                                                                              true,
                                                                              ordering_block,
                                                                              duplicates_ordering_proc )
  index_instance.attribute_name = attribute
  indexes[ attribute ] = attribute_indexes[ attribute ] = index_instance

  return self

end

#attr_index_with_duplicates(attribute_name, ...) ⇒ Object

Declare an index permitting duplicates on attribute(s).

Parameters:

  • attribute_name

    Name of object property to index. Creates accessor if method by name does not already exist.

Returns:

  • self



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/persistence/object/complex/class_instance.rb', line 88

def attr_index_with_duplicates( attribute )

 index_instance = ::Persistence::Object::Complex::Index::AttributeIndex.new( attribute, 
                                                                             instance_persistence_bucket, 
                                                                             true )
 index_instance.attribute_name = attribute
 indexes[ attribute ] = attribute_indexes[ attribute ] = index_instance

 return self

end

#cease!(*args) ⇒ Object

cease! #



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/persistence/object/complex/class_instance.rb', line 159

def cease!( *args )

  if persistence_hash_in_port = super

    persistence_hash_in_port.each do |this_attribute, this_value|

      if this_value.is_a?( ::Persistence::Object::Complex::ComplexObject ) and 
         delete_cascades?( global_id, this_value.persistence_id )

        this_value.cease!

      end

    end

  end
  
  return persistence_hash_in_port
  
end

#has_attribute_index?(index_name, ...) ⇒ true, false

Query whether attribute index(es) exist for object.

Parameters:

  • index_name

    Name of requested index.

Returns:

  • (true, false)

    Whether index(es) exist.



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/persistence/object/complex/class_instance.rb', line 143

def has_attribute_index?( *attributes )

  has_index = false

  attributes.each do |this_attribute|
    break unless has_index = attribute_indexes.has_key?( this_attribute.accessor_name )
  end

  return has_index

end

#persists_flatCompositingHash{Symbol,String=>true}

Hash that tracks attributes specified to persist as if they are flat objects.

Returns:

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

    Hash with attribute details.



265
# File 'lib/persistence/object/complex/class_instance.rb', line 265

attr_unique_array :persists_flat

#has_attribute_index?(attribute_name, ...) ⇒ true, false

Query whether attribute(s) are being treated explicitly as flat objects.

Parameters:

  • attribute_name

    Attribute(s) in question.

Returns:

  • (true, false)

    Whether attributes(es) are being treated explicitly as flat objects.



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/persistence/object/complex/class_instance.rb', line 238

def persists_flat?( *attributes )

  should_persist_flat = false

  if attributes.empty?
    should_persist_flat = persists_flat.include?( nil )
  else
    attributes.each do |this_attribute|
      break unless should_persist_flat = persists_flat.include?( this_attribute )
    end
  end
  
  return should_persist_flat
  
end