Class: DefaultModelSerializer

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

Constant Summary collapse

Snapshot_Extension =
'snapshot'

Instance Method Summary collapse

Constructor Details

#initialize(iomanager, marshaller) ⇒ DefaultModelSerializer

Returns a new instance of DefaultModelSerializer.



5
6
7
# File 'lib/internal/serializer.rb', line 5

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

Instance Method Details

#dump(object_model) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/internal/serializer.rb', line 9

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



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/internal/serializer.rb', line 18

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