Class: Depot::ManifestStore

Inherits:
Object
  • Object
show all
Defined in:
lib/depot/manifest_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir = Paths.manifests_dir) ⇒ ManifestStore

Returns a new instance of ManifestStore.



11
12
13
# File 'lib/depot/manifest_store.rb', line 11

def initialize(dir = Paths.manifests_dir)
  @dir = dir
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



9
10
11
# File 'lib/depot/manifest_store.rb', line 9

def dir
  @dir
end

Instance Method Details

#allObject



15
16
17
# File 'lib/depot/manifest_store.rb', line 15

def all
  Dir.glob(File.join(dir, "*.json")).sort.filter_map { |path| read_file(path) }
end

#delete(app_id) ⇒ Object



37
38
39
# File 'lib/depot/manifest_store.rb', line 37

def delete(app_id)
  FileUtils.rm_f(manifest_path(app_id))
end

#find(app_id) ⇒ Object



23
24
25
26
27
28
# File 'lib/depot/manifest_store.rb', line 23

def find(app_id)
  path = manifest_path(app_id)
  return nil unless File.exist?(path)

  read_file(path)
end

#idsObject



19
20
21
# File 'lib/depot/manifest_store.rb', line 19

def ids
  all.map { |manifest| manifest.fetch("app_id") }
end

#manifest_path(app_id) ⇒ Object



41
42
43
# File 'lib/depot/manifest_store.rb', line 41

def manifest_path(app_id)
  File.join(dir, "#{app_id}.json")
end

#write(manifest) ⇒ Object



30
31
32
33
34
35
# File 'lib/depot/manifest_store.rb', line 30

def write(manifest)
  FileUtils.mkdir_p(dir)
  path = manifest_path(manifest.fetch("app_id"))
  File.write(path, JSON.pretty_generate(manifest) + "\n")
  path
end