Module: Persistence::Port::PortInterface

Includes:
Object::Flat::File::FilePersistence
Included in:
Persistence::Port
Defined in:
lib/persistence/port/port_interface.rb

Overview

Interface for Port implementation. Provided separately for easy overriding.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Object::Flat::File::FilePersistence

#persist_files_by_content!, #persist_files_by_path!

Instance Attribute Details

#bucketsHash{Symbol,String=>Persistence::Port::Bucket] Bucket Hash. (readonly)

Returns Hash{Symbol,String=>Persistence::Port::Bucket] Bucket Hash.

Returns:



146
147
148
# File 'lib/persistence/port/port_interface.rb', line 146

def buckets
  @buckets
end

#Hash of buckets.(ofbuckets.) ⇒ Hash{Symbol,String=>Persistence::Port::Bucket] Bucket Hash. (readonly)

Returns Hash{Symbol,String=>Persistence::Port::Bucket] Bucket Hash.

Returns:



146
# File 'lib/persistence/port/port_interface.rb', line 146

attr_reader :buckets

#nameSymbol, String (readonly)

Returns Name.

Returns:

  • (Symbol, String)

    Name.



62
63
64
# File 'lib/persistence/port/port_interface.rb', line 62

def name
  @name
end

#Name of bucket(ofbucket) ⇒ Symbol, String (readonly)

Returns Name.

Returns:

  • (Symbol, String)

    Name.



62
# File 'lib/persistence/port/port_interface.rb', line 62

attr_reader :name

Instance Method Details

#adapterObject

Retrieve parallel adapter instance.

Returns:

  • (Object)

    Adapter instance.



43
44
45
46
47
48
49
50
51
# File 'lib/persistence/port/port_interface.rb', line 43

def adapter
  
  unless @adapter
    raise 'Persistence port must be enabled first.'
  end
  
  return @adapter
  
end

#delete_object!(global_id) ⇒ String

Delete object in persistence port.

Parameters:

  • global_id

    Object persistence ID.

Returns:

  • (String)

    Name of bucket.



277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/persistence/port/port_interface.rb', line 277

def delete_object!( global_id )

  persistence_hash_from_port = nil
  
  bucket = get_bucket_name_for_object_id( global_id )
  
  if bucket
    persistence_hash_from_port = persistence_bucket( bucket ).delete_object!( global_id )
  end
  
  return persistence_hash_from_port
  
end

#disableObject

Disable port.

Returns:

  • self



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/persistence/port/port_interface.rb', line 91

def disable

  @enabled = false

  @instances.delete_if do |this_instance|
    this_instance.instance_persistence_port = nil
    true
  end

  @buckets.each do |this_bucket_name, this_bucket|
    this_bucket.disable
  end

  @adapter.disable

  return self

end

#disabled?true, false

Query whether port is disabled.

Returns:

  • (true, false)

    Whether port is disabled.



132
133
134
135
# File 'lib/persistence/port/port_interface.rb', line 132

def disabled?

  return ! @enabled
end

#enableObject

Enable port.

Returns:

  • self



73
74
75
76
77
78
79
80
# File 'lib/persistence/port/port_interface.rb', line 73

def enable
  @enabled = true
  @adapter.enable
  @buckets.each do |this_bucket_name, this_bucket|
    this_bucket.initialize_for_port( self )
  end
  return self
end

#enabled?true, false

Query whether port is enabled.

Returns:

  • (true, false)

    Whether port is enabled.



119
120
121
# File 'lib/persistence/port/port_interface.rb', line 119

def enabled?
  return @enabled
end

#get_bucket_name_for_object_id(global_id) ⇒ String

Use Object persistence ID to retrieve the name of the bucket in which object is currently being stored.

Parameters:

  • global_id

    Object persistence ID that owns indexed entries.

Returns:

  • (String)

    Name of bucket.



222
223
224
225
226
# File 'lib/persistence/port/port_interface.rb', line 222

def get_bucket_name_for_object_id( global_id )
  
  return adapter.get_bucket_name_for_object_id( global_id )

end

#get_class_for_object_id(global_id) ⇒ String

Use Object persistence ID to retrieve the class of the object.

Parameters:

  • global_id

    Object persistence ID that owns indexed entries.

Returns:

  • (String)

    Name of bucket.



241
242
243
244
245
# File 'lib/persistence/port/port_interface.rb', line 241

def get_class_for_object_id( global_id )

  return adapter.get_class_for_object_id( global_id )

end

#get_flat_object(global_id) ⇒ Object

Get flat object from persistence port.

Parameters:

  • global_id

    Object persistence ID to persist from port.

Returns:

  • (Object)

    Persisted object instance.



331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/persistence/port/port_interface.rb', line 331

def get_flat_object( global_id )
  
  flat_object = nil
  
  bucket = get_bucket_name_for_object_id( global_id )

  if bucket
    flat_object = persistence_bucket( bucket ).get_flat_object( global_id )
  end
  
  return flat_object
  
end

#get_object(global_id) ⇒ Object

Get object from persistence port.

Parameters:

  • global_id

    Object persistence ID.

Returns:

  • (Object)

    Persisted object instance.



304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/persistence/port/port_interface.rb', line 304

def get_object( global_id )
      
  object = nil
      
  bucket = get_bucket_name_for_object_id( global_id )
  
  if bucket
    object = persistence_bucket( bucket ).get_object( global_id )
  end

  return object
  
end

#initialize(port_name, adapter_instance) ⇒ Object

Parameters:

  • port_name

    Name to use to identify port instance.

  • adapter_instance

    Adapter instance for which port instance will be operative.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/persistence/port/port_interface.rb', line 19

def initialize( port_name, adapter_instance )

  super() if defined?( super )
  
  @buckets = { }
  
  @instances = ::Array::Unique.new
  
  @name    = port_name
  @adapter = adapter_instance
  
  @enabled = false
  
end

#initialize_persistence_bucket_from_instance(bucket_instance) ⇒ Object

Use a bucket instance that has already been created with this port.



174
175
176
177
178
179
180
181
182
# File 'lib/persistence/port/port_interface.rb', line 174

def initialize_persistence_bucket_from_instance( bucket_instance )

  @buckets[ bucket_instance.name.to_sym ] = bucket_instance

  bucket_instance.initialize_for_port( self )
  
  return bucket_instance
  
end

#persistence_bucket(bucket_name) ⇒ Persistence::Port::Bucket

Get persistence bucket configured for this port.

Parameters:

  • bucket_name

    Name of bucket.

Returns:



195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/persistence/port/port_interface.rb', line 195

def persistence_bucket( bucket_name )
  
  bucket_instance = nil

  bucket_name = bucket_name.to_sym

  unless bucket_instance = @buckets[ bucket_name ]
    @buckets[ bucket_name ] = bucket_instance = ::Persistence::Port::Bucket.new( self, bucket_name )
  end      
  
  return bucket_instance
  
end

#persists_file_paths_as_strings?Boolean

persists_file_paths_as_strings? #

Returns:

  • (Boolean)


385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/persistence/port/port_interface.rb', line 385

def persists_file_paths_as_strings?
  
  persists_file_paths_as_strings = nil
  
  persists_file_paths_as_strings = super
  
  if persists_file_paths_as_strings.nil?
    persists_file_paths_as_strings = ::Persistence.persists_file_paths_as_strings?
  end
  
  return persists_file_paths_as_strings
  
end

#persists_files_by_content?Boolean

persists_files_by_content? #

Returns:

  • (Boolean)


349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/persistence/port/port_interface.rb', line 349

def persists_files_by_content?
  
  persists_files_by_content = nil
  
  persists_files_by_content = super
  
  if persists_files_by_content.nil?
    persists_files_by_content = ::Persistence.persists_files_by_content?
  end
  
  return persists_files_by_content
  
end

#persists_files_by_path?Boolean

persists_files_by_path? #

Returns:

  • (Boolean)


367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/persistence/port/port_interface.rb', line 367

def persists_files_by_path?
  
  persists_files_by_path = nil
  
  persists_files_by_path = super
  
  if persists_files_by_path.nil?
    persists_files_by_path = ::Persistence.persists_files_by_path?
  end
  
  return persists_files_by_path
  
end

#put_object!(object) ⇒ Object

Persist object in persistence port. Object configuration will be used to determine where and how.

Returns:

  • (Object)

    Object persistence ID



258
259
260
261
262
# File 'lib/persistence/port/port_interface.rb', line 258

def put_object!( object )    

  return object.persistence_bucket.put_object!( object )

end

#register_instance(instance) ⇒ Object

Register an instance as using this port. This is used to disable references to port when port is disabled.



157
158
159
160
161
162
163
# File 'lib/persistence/port/port_interface.rb', line 157

def register_instance( instance )
  
  @instances.push( instance )
  
  return self
  
end