Class: Nandi::Lockfile
- Inherits:
-
Object
- Object
- Nandi::Lockfile
- Defined in:
- lib/nandi/lockfile.rb
Class Attribute Summary collapse
-
.lockfile ⇒ Object
Returns the value of attribute lockfile.
Class Method Summary collapse
- .add(file_name:, source_digest:, compiled_digest:) ⇒ Object
- .create! ⇒ Object
- .file_present? ⇒ Boolean
- .get(file_name) ⇒ Object
- .load! ⇒ Object
- .path ⇒ Object
- .persist! ⇒ Object
Class Attribute Details
.lockfile ⇒ Object
Returns the value of attribute lockfile.
55 56 57 |
# File 'lib/nandi/lockfile.rb', line 55 def lockfile @lockfile end |
Class Method Details
.add(file_name:, source_digest:, compiled_digest:) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/nandi/lockfile.rb', line 18 def add(file_name:, source_digest:, compiled_digest:) load! lockfile[file_name] = { source_digest: source_digest, compiled_digest: compiled_digest, } end |
.create! ⇒ Object
12 13 14 15 16 |
# File 'lib/nandi/lockfile.rb', line 12 def create! return if file_present? File.write(path, {}.to_yaml) end |
.file_present? ⇒ Boolean
8 9 10 |
# File 'lib/nandi/lockfile.rb', line 8 def file_present? File.exist?(path) end |
.get(file_name) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/nandi/lockfile.rb', line 27 def get(file_name) load! { source_digest: lockfile.dig(file_name, :source_digest), compiled_digest: lockfile.dig(file_name, :compiled_digest), } end |
.load! ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/nandi/lockfile.rb', line 36 def load! return lockfile if lockfile Nandi::Lockfile.create! unless Nandi::Lockfile.file_present? @lockfile = YAML.safe_load(File.read(path)).with_indifferent_access end |
.path ⇒ Object
48 49 50 51 52 53 |
# File 'lib/nandi/lockfile.rb', line 48 def path File.join( Nandi.config.lockfile_directory, ".nandilock.yml", ) end |
.persist! ⇒ Object
44 45 46 |
# File 'lib/nandi/lockfile.rb', line 44 def persist! File.write(path, lockfile.to_h.deep_stringify_keys.to_yaml) end |