Class: Stable::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/stable/registry.rb

Class Method Summary collapse

Class Method Details

.appsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/stable/registry.rb', line 17

def self.apps
  return [] unless File.exist?(file_path)

  data = YAML.load_file(file_path) || []
  data.map do |entry|
    next entry unless entry.is_a?(Hash)

    entry.each_with_object({}) do |(k, v), memo|
      key = k.is_a?(String) ? k.to_sym : k
      memo[key] = v
    end
  end
end

.file_pathObject



8
9
10
# File 'lib/stable/registry.rb', line 8

def self.file_path
  Stable::Paths.apps_file
end

.save(apps) ⇒ Object



12
13
14
15
# File 'lib/stable/registry.rb', line 12

def self.save(apps)
  FileUtils.mkdir_p(Stable.root)
  File.write(file_path, apps.to_yaml)
end