Module: Array::Compositing::ArrayInterface

Extended by:
Module::Cluster
Includes:
Hooked::ArrayInterface
Included in:
Array::Compositing
Defined in:
lib/array/compositing/array_interface.rb

Defined Under Namespace

Classes: ParentIndexStruct

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parent_composite_objectObject Also known as: parent_composite_array

parent_composite_object #

parent_composite_array   #


80
81
82
# File 'lib/array/compositing/array_interface.rb', line 80

def parent_composite_object
  @parent_composite_object
end

Instance Method Details

#==(object) ⇒ Object

#



157
158
159
160
161
162
163
# File 'lib/array/compositing/array_interface.rb', line 157

def ==( object )
  
  load_parent_state

  return super
  
end

#[](local_index) ⇒ Object

#



212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/array/compositing/array_interface.rb', line 212

def []( local_index )

  return_value = nil

  if @parent_index_map and @parent_index_map.requires_lookup?( local_index )
    return_value = lazy_set_parent_element_in_self( local_index )
  else
    return_value = super
  end

  return return_value

end

#[]=(local_index, object) ⇒ Object Also known as: store

[]= #



230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/array/compositing/array_interface.rb', line 230

def []=( local_index, object )
  
  super

  @sub_composite_arrays.each do |this_sub_array|
    this_sub_array.instance_eval do
      update_for_parent_set( local_index, object )
    end
  end

  return object

end

#child_post_delete_hook(index, object) ⇒ Object

child_post_delete_hook #



145
146
147
148
149
# File 'lib/array/compositing/array_interface.rb', line 145

def child_post_delete_hook( index, object )
  
  return object
  
end

#child_post_set_hook(index, object, is_insert = false) ⇒ Object

child_post_set_hook #



124
125
126
127
128
# File 'lib/array/compositing/array_interface.rb', line 124

def child_post_set_hook( index, object, is_insert = false )
  
  return object
  
end

#child_pre_delete_hook(index) ⇒ Object

child_pre_delete_hook #



134
135
136
137
138
139
# File 'lib/array/compositing/array_interface.rb', line 134

def child_pre_delete_hook( index )
  
  # false means delete does not take place
  return true
  
end

#child_pre_set_hook(index, object, is_insert = false) ⇒ Object

child_pre_set_hook #



114
115
116
117
118
# File 'lib/array/compositing/array_interface.rb', line 114

def child_pre_set_hook( index, object, is_insert = false )

  return object
  
end

#delete_at(local_index) ⇒ Object

delete_at #



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/array/compositing/array_interface.rb', line 250

def delete_at( local_index )
  
  if @parent_index_map
    @parent_index_map.local_delete_at( local_index )
  end
  
  deleted_object = non_cascading_delete_at( local_index )

  @sub_composite_arrays.each do |this_sub_array|
    this_sub_array.instance_eval do
      update_for_parent_delete_at( local_index, deleted_object )
    end
  end

  return deleted_object

end

#each(*args, &block) ⇒ Object

each #



181
182
183
184
185
186
187
# File 'lib/array/compositing/array_interface.rb', line 181

def each( *args, & block )

  load_parent_state
 
  return super
  
end

#freeze!Object

freezes configuration and prevents ancestors from changing this configuration in the future



273
274
275
276
277
278
279
280
281
282
# File 'lib/array/compositing/array_interface.rb', line 273

def freeze!

  # unregister with parent composite so we don't get future updates from it
  if @parent_composite_object
    @parent_composite_object.unregister_sub_composite_array( self )
  end

  return self

end

#include?(object) ⇒ Boolean

include? #

Returns:

  • (Boolean)


193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/array/compositing/array_interface.rb', line 193

def include?( object )

  includes = false
  
  each do |this_member|
    if this_member == object
      includes = true 
      break
    end
  end

  return includes
  
end

#initialize(parent_composite_array = nil, configuration_instance = nil, *args) ⇒ Object

initialize #



36
37
38
39
40
41
42
43
44
45
# File 'lib/array/compositing/array_interface.rb', line 36

def initialize( parent_composite_array = nil, configuration_instance = nil, *args )

  super( configuration_instance, *args )
  
  # arrays that inherit from us
  @sub_composite_arrays = [ ]

  initialize_for_parent( parent_composite_array )

end

#initialize_for_parent(parent_composite_array) ⇒ Object

initialize_for_parent #



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/array/compositing/array_interface.rb', line 53

def initialize_for_parent( parent_composite_array )

  if @parent_composite_object = parent_composite_array

    @parent_index_map = ::Array::Compositing::ParentIndexMap.new

    @parent_composite_object.register_sub_composite_array( self )
    
    # record in our parent index map that parent has elements that have been inserted      
    parent_element_count = @parent_composite_object.count
    @parent_index_map.parent_insert( 0, parent_element_count )
    
    # initialize contents of self from parent contents
    parent_element_count.times do |this_time|
      # placeholders so we don't have to stub :count, etc.
      undecorated_insert( 0, nil )
    end
    
  end
  
end

#inspectObject

inspect #



169
170
171
172
173
174
175
# File 'lib/array/compositing/array_interface.rb', line 169

def inspect

  load_parent_state
 
  return super
  
end

#register_sub_composite_array(sub_composite_array) ⇒ Object

register_sub_composite_array #



88
89
90
91
92
93
94
# File 'lib/array/compositing/array_interface.rb', line 88

def register_sub_composite_array( sub_composite_array )

  @sub_composite_arrays.push( sub_composite_array )

  return self

end

#unregister_sub_composite_array(sub_composite_array) ⇒ Object

unregister_sub_composite_array #



100
101
102
103
104
105
106
# File 'lib/array/compositing/array_interface.rb', line 100

def unregister_sub_composite_array( sub_composite_array )

  @sub_composite_arrays.delete( sub_composite_array )

  return self

end