Module: Persistence::Adapter::FlatFile::AdapterInterface

Includes:
Abstract::EnableDisable, Abstract::PrimaryKey::IDPropertyString, PathHelpers, Serialization
Included in:
Persistence::Adapter::FlatFile, Marshal, YAML::AdapterInterface
Defined in:
lib/persistence/adapter/flat_file/adapter_interface.rb

Constant Summary collapse

Delimiter =
'.'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parent_bucketObject

Returns the value of attribute parent_bucket.


12
13
14
# File 'lib/persistence/adapter/flat_file/adapter_interface.rb', line 12

def parent_bucket
  @parent_bucket
end

Instance Method Details

#adapter_classObject

adapter_class #


35
36
37
38
39
# File 'lib/persistence/adapter/flat_file/adapter_interface.rb', line 35

def adapter_class
  
  return self.class
  
end

#delete_bucket_for_object_id(global_id) ⇒ Object

delete_bucket_for_object_id #


86
87
88
89
90
91
92
# File 'lib/persistence/adapter/flat_file/adapter_interface.rb', line 86

def delete_bucket_for_object_id( global_id )

  file__bucket = file__bucket_name_for_id( global_id )
  
  File.delete( file__bucket )
  
end

#delete_class_for_object_id(global_id) ⇒ Object

delete_class_for_object_id #


98
99
100
101
102
103
104
# File 'lib/persistence/adapter/flat_file/adapter_interface.rb', line 98

def delete_class_for_object_id( global_id )

  file__class = file__class_for_id( global_id )

  File.delete( file__class )

end

#ensure_object_has_globally_unique_id(object) ⇒ Object

ensure_object_has_globally_unique_id #


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/persistence/adapter/flat_file/adapter_interface.rb', line 110

def ensure_object_has_globally_unique_id( object )

  unless global_id = object.persistence_id
            
    # iterate the sequence by 1 and use the ID
    object.persistence_id = global_id = iterate_id_sequence
    
    # store bucket name for ID
    store_bucket_name_for_id( object.persistence_bucket.name, global_id )

    # store class for ID
    store_class_for_id( object.class, global_id )

  end    

  return global_id

end

#get_bucket_name_for_object_id(global_id) ⇒ Object

get_bucket_name_for_object_id #


62
63
64
65
66
67
68
# File 'lib/persistence/adapter/flat_file/adapter_interface.rb', line 62

def get_bucket_name_for_object_id( global_id )
  
  file__bucket = file__bucket_name_for_id( global_id )
  
  return open_read_unserialize_and_close( file__bucket )

end

#get_class_for_object_id(global_id) ⇒ Object

get_class_for_object_id #


74
75
76
77
78
79
80
# File 'lib/persistence/adapter/flat_file/adapter_interface.rb', line 74

def get_class_for_object_id( global_id )
  
  file__class = file__class_for_id( global_id )
  
  return open_read_unserialize_and_close( file__class )

end

#initialize(home_directory) ⇒ Object

initialize #


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/persistence/adapter/flat_file/adapter_interface.rb', line 18

def initialize( home_directory )
  
  super( home_directory )

  @buckets = { }

  # make sure we have a sequence
  unless File.exists?( file__global_id_sequence )
    create_or_update_value_serialize_and_write( file__global_id_sequence, -1 )
  end
  
end

#persistence_bucket(bucket_name) ⇒ Object

persistence_bucket #


45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/persistence/adapter/flat_file/adapter_interface.rb', line 45

def persistence_bucket( bucket_name )
  
  bucket_instance = nil

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

  return bucket_instance

end