Class: GitCompound::Lock
- Inherits:
-
Object
- Object
- GitCompound::Lock
- Defined in:
- lib/git_compound/lock.rb
Overview
Class that represents lock file
Constant Summary collapse
- FILENAME =
'.gitcompound.lock'
Class Method Summary collapse
Instance Method Summary collapse
- #clean ⇒ Object
- #components ⇒ Object
- #contents ⇒ Object
- #find(component) ⇒ Object
-
#initialize(file = FILENAME) ⇒ Lock
constructor
A new instance of Lock.
- #lock_component(component) ⇒ Object
- #lock_manifest(manifest) ⇒ Object
- #manifest ⇒ Object
- #process(worker) ⇒ Object
- #write ⇒ Object
Constructor Details
Class Method Details
.exist? ⇒ Boolean
9 10 11 |
# File 'lib/git_compound/lock.rb', line 9 def self.exist? File.exist?(FILENAME) end |
Instance Method Details
#clean ⇒ Object
19 20 21 22 |
# File 'lib/git_compound/lock.rb', line 19 def clean @locked = { manifest: '', components: [] } self end |
#components ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/git_compound/lock.rb', line 36 def components @locked[:components].to_a.map do |locked| Component.new(locked[:name].to_sym) do sha locked[:sha] source locked[:source] destination locked[:destination] end end end |
#contents ⇒ Object
46 47 48 |
# File 'lib/git_compound/lock.rb', line 46 def contents @locked end |
#find(component) ⇒ Object
50 51 52 53 54 |
# File 'lib/git_compound/lock.rb', line 50 def find(component) components.find do |locked_component| locked_component.path == component.path end end |
#lock_component(component) ⇒ Object
28 29 30 |
# File 'lib/git_compound/lock.rb', line 28 def lock_component(component) @locked[:components] << component.to_hash end |
#lock_manifest(manifest) ⇒ Object
24 25 26 |
# File 'lib/git_compound/lock.rb', line 24 def lock_manifest(manifest) @locked[:manifest] = manifest.md5sum end |
#manifest ⇒ Object
32 33 34 |
# File 'lib/git_compound/lock.rb', line 32 def manifest @locked[:manifest] end |
#process(worker) ⇒ Object
56 57 58 |
# File 'lib/git_compound/lock.rb', line 56 def process(worker) components.each { |component| worker.visit_component(component) } end |
#write ⇒ Object
60 61 62 |
# File 'lib/git_compound/lock.rb', line 60 def write File.open(@file, 'w') { |f| f.puts @locked.to_yaml } end |