Class: MultiRepo::LockFile
- Inherits:
-
TrackingFile
- Object
- TrackingFile
- MultiRepo::LockFile
- Defined in:
- lib/multirepo/files/lock-file.rb
Constant Summary collapse
- FILENAME =
".multirepo.lock"
Instance Method Summary collapse
- #ensure_access(file, error_message, &check) ⇒ Object
- #exists? ⇒ Boolean
- #file ⇒ Object
- #filename ⇒ Object
-
#initialize(path) ⇒ LockFile
constructor
A new instance of LockFile.
- #load_entries ⇒ Object
- #update ⇒ Object
- #validate! ⇒ Object
- #validate_entry!(entry) ⇒ Object
Methods inherited from TrackingFile
Constructor Details
#initialize(path) ⇒ LockFile
Returns a new instance of LockFile.
12 13 14 |
# File 'lib/multirepo/files/lock-file.rb', line 12 def initialize(path) @path = path end |
Instance Method Details
#ensure_access(file, error_message, &check) ⇒ Object
58 59 60 |
# File 'lib/multirepo/files/lock-file.rb', line 58 def ensure_access(file, , &check) fail MultiRepoException, if File.exists?(file) && !check.call(File.stat(file)) end |
#exists? ⇒ Boolean
24 25 26 |
# File 'lib/multirepo/files/lock-file.rb', line 24 def exists? File.exist?(file) end |
#file ⇒ Object
16 17 18 |
# File 'lib/multirepo/files/lock-file.rb', line 16 def file File.join(@path, FILENAME) end |
#filename ⇒ Object
20 21 22 |
# File 'lib/multirepo/files/lock-file.rb', line 20 def filename FILENAME end |
#load_entries ⇒ Object
28 29 30 31 |
# File 'lib/multirepo/files/lock-file.rb', line 28 def load_entries ensure_access(file, "Can't read lock file (permissions)") { |stat| stat.readable? } Psych.load(File.read(file)) end |
#update ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/multirepo/files/lock-file.rb', line 33 def update ensure_access(file, "Can't write lock file (permissions)") { |stat| stat.writable? } config_entries = ConfigFile.new(@path).load_entries lock_entries = config_entries.map { |c| LockEntry.new(c) } content = Psych.dump(lock_entries) return update_internal(file, content) end |
#validate! ⇒ Object
41 42 43 |
# File 'lib/multirepo/files/lock-file.rb', line 41 def validate! load_entries.all? { |e| validate_entry! e } end |
#validate_entry!(entry) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/multirepo/files/lock-file.rb', line 45 def validate_entry!(entry) valid = true # head valid &= /\b([a-f0-9]{40})\b/ =~ entry.head.to_s # branch GitRunner.run(@path, "check-ref-format --branch #{entry.branch}", Verbosity::OUTPUT_NEVER) valid &= (entry.branch == "" || GitRunner.last_command_succeeded) return valid end |