Module: ConcurrentPipeline::Stores::Yaml

Defined in:
lib/concurrent_pipeline/stores/yaml.rb,
lib/concurrent_pipeline/stores/yaml/db.rb,
lib/concurrent_pipeline/stores/yaml/history.rb

Defined Under Namespace

Classes: Db, History

Class Method Summary collapse

Class Method Details

.build_writer(data:, dir:, registry:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/concurrent_pipeline/stores/yaml.rb', line 12

def self.build_writer(data:, dir:, registry:)
  data_path = File.join(dir, "data.yml")
  versions_path = File.join(dir, "versions.yml")

  after_apply = ->(changesets) do
    File.write(data_path, data.to_yaml)
    File.open(versions_path, "a") do |f|
      changesets
        .map { _1.as_json.to_yaml }
        .join("\n")
        .then { f.puts(_1)}
    end
  end

  db = Db.new(data: data, registry: registry, after_apply: after_apply)

  changeset = db.changeset
  changeset.deltas << Changeset::InitialDelta.new(data: data)
  db.apply(changeset)
  db
end

.history(dir:, registry:) ⇒ Object



34
35
36
37
# File 'lib/concurrent_pipeline/stores/yaml.rb', line 34

def self.history(dir:, registry:)
  path = File.join(dir, "versions.yml")
  History.new(registry: registry, path: path)
end