Class: VagrantGitHooks::Util::Manifest
- Inherits:
-
Object
- Object
- VagrantGitHooks::Util::Manifest
- Defined in:
- lib/vagrant-git-hooks/util/manifest.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(path) ⇒ Manifest
constructor
A new instance of Manifest.
-
#load ⇒ Hash
Loads the hook manifest from disk.
-
#save(data) ⇒ Hash
Saves normalized hook manifest data.
Constructor Details
#initialize(path) ⇒ Manifest
Returns a new instance of Manifest.
11 12 13 |
# File 'lib/vagrant-git-hooks/util/manifest.rb', line 11 def initialize(path) @path = path.to_s end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/vagrant-git-hooks/util/manifest.rb', line 9 def path @path end |
Instance Method Details
#clear ⇒ Object
40 41 42 43 44 45 |
# File 'lib/vagrant-git-hooks/util/manifest.rb', line 40 def clear File.delete(@path) if File.exist?(@path) true rescue StandardError false end |
#load ⇒ Hash
Loads the hook manifest from disk.
Invalid or missing manifest data is treated as empty so hook commands can recover from interrupted runs.
21 22 23 24 25 26 27 28 |
# File 'lib/vagrant-git-hooks/util/manifest.rb', line 21 def load return empty unless File.exist?(@path) data = JSON.parse(File.read(@path)) data.is_a?(Hash) ? normalize(data) : empty rescue StandardError empty end |
#save(data) ⇒ Hash
Saves normalized hook manifest data.
34 35 36 37 38 |
# File 'lib/vagrant-git-hooks/util/manifest.rb', line 34 def save(data) FileUtils.mkdir_p(File.dirname(@path)) File.write(@path, JSON.pretty_generate(normalize(data))) data end |