Class: VersionIndependentSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/internal/serializer.rb

Overview

TODO: VersionIndependentSerializer is intended to handle small modifications in the object model, like new fields or even excluded fields, without breaking the existing snapshots

Constant Summary collapse

Snapshot_Extension =
'version-ind-snapshot'

Instance Method Summary collapse

Constructor Details

#initialize(iomanager, marshaller) ⇒ VersionIndependentSerializer

Returns a new instance of VersionIndependentSerializer.



42
43
44
# File 'lib/internal/serializer.rb', line 42

def initialize( iomanager, marshaller )
  @iomanager, @marshaller = iomanager, marshaller
end

Instance Method Details

#dump(object_model) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/internal/serializer.rb', line 46

def dump( object_model )
  begin
    stream = @iomanager.create_new_stream( Snapshot_Extension )
    @marshaller.serialize_to_stream( object_model, stream )
  ensure
    stream.close
  end
end

#loadObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/internal/serializer.rb', line 55

def load()
  object_model = nil
  stream = @iomanager.obtain_latest_read_stream( Snapshot_Extension )
  return nil if stream.nil?
  
  begin
    object_model = @marshaller.restore( stream )
  ensure
    stream.close
  end
  
  object_model
end