Class: HPrevalence::StorageManager

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

Instance Method Summary collapse

Constructor Details

#initialize(target_dir, iomanager = FileIOManager.new(target_dir), marshaller = DefaultMarshaller.new(), model_serializer = DefaultModelSerializer.new(iomanager, marshaller)) ⇒ StorageManager

Returns a new instance of StorageManager.



6
7
8
9
10
11
12
13
14
15
# File 'lib/internal/store_manager.rb', line 6

def initialize( 
      target_dir, 
      iomanager = FileIOManager.new(target_dir), 
      marshaller = DefaultMarshaller.new(), 
      model_serializer = DefaultModelSerializer.new(iomanager, marshaller) )

  @model_serializer = model_serializer
  @logger = CommandLogger.new(iomanager, marshaller) 
  @comand_store = nil
end

Instance Method Details

#closeObject



34
35
36
37
# File 'lib/internal/store_manager.rb', line 34

def close
  @comand_store.close unless @comand_store.nil?
  @comand_store = nil
end

#restore(system) ⇒ Object



17
18
19
20
21
# File 'lib/internal/store_manager.rb', line 17

def restore( system )
  system = restore_snapshot( system )
  restore_commands( system )
  system
end

#store(command) ⇒ Object



23
24
25
26
# File 'lib/internal/store_manager.rb', line 23

def store( command )
  ensure_command_store
  @comand_store << command
end

#take_snapshot(system) ⇒ Object



28
29
30
31
32
# File 'lib/internal/store_manager.rb', line 28

def take_snapshot( system )
  @model_serializer.dump( system )
  close()
  @logger.reset_commands
end