Class: RubyCms::Lockfile

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_cms/lockfile.rb

Overview

Reads/writes .ruby_cms.yml at the host app root: which modules are installed.

Constant Summary collapse

FILENAME =
".ruby_cms.yml"

Instance Method Summary collapse

Constructor Details

#initialize(app_root) ⇒ Lockfile

Returns a new instance of Lockfile.



11
12
13
# File 'lib/ruby_cms/lockfile.rb', line 11

def initialize(app_root)
  @path = Pathname.new(app_root).join(FILENAME)
end

Instance Method Details

#add!(modules, version:) ⇒ Object



39
40
41
# File 'lib/ruby_cms/lockfile.rb', line 39

def add!(modules, version:)
  write!(modules: (self.modules + Array(modules)).uniq, version: version)
end

#excludesObject

App-relative globs the host never wants overwritten by update/sync.



22
23
24
25
26
# File 'lib/ruby_cms/lockfile.rb', line 22

def excludes
  return [] unless @path.exist?

  Array(data["exclude"]).map(&:to_s)
end

#modulesObject



15
16
17
18
19
# File 'lib/ruby_cms/lockfile.rb', line 15

def modules
  return [] unless @path.exist?

  Array(data["modules"]).map(&:to_sym)
end

#versionObject



28
29
30
# File 'lib/ruby_cms/lockfile.rb', line 28

def version
  data["version"] if @path.exist?
end

#write!(modules:, version:) ⇒ Object



32
33
34
35
36
37
# File 'lib/ruby_cms/lockfile.rb', line 32

def write!(modules:, version:)
  existing_exclude = @path.exist? ? Array(data["exclude"]) : []
  @data = { "version" => version, "modules" => modules.map(&:to_s).uniq.sort }
  @data["exclude"] = existing_exclude unless existing_exclude.empty?
  @path.write(YAML.dump(@data))
end