Class: RCrewAI::Flow::FileStateStore

Inherits:
Object
  • Object
show all
Defined in:
lib/rcrewai/flow/state_store.rb

Overview

Stores each state as a JSON file named .json under a directory.

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ FileStateStore

Returns a new instance of FileStateStore.



27
28
29
30
# File 'lib/rcrewai/flow/state_store.rb', line 27

def initialize(dir)
  @dir = dir
  FileUtils.mkdir_p(@dir)
end

Instance Method Details

#load(id) ⇒ Object



36
37
38
39
40
41
# File 'lib/rcrewai/flow/state_store.rb', line 36

def load(id)
  path = path_for(id)
  return nil unless File.exist?(path)

  JSON.parse(File.read(path))
end

#save(id, hash) ⇒ Object



32
33
34
# File 'lib/rcrewai/flow/state_store.rb', line 32

def save(id, hash)
  File.write(path_for(id), JSON.pretty_generate(hash))
end