Class: MultiRepo::MetaFile

Inherits:
TrackingFile show all
Defined in:
lib/multirepo/files/meta-file.rb

Constant Summary collapse

FILENAME =
".multirepo.meta"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TrackingFile

#update_internal

Constructor Details

#initialize(path) ⇒ MetaFile

Returns a new instance of MetaFile.



15
16
17
18
# File 'lib/multirepo/files/meta-file.rb', line 15

def initialize(path)
  @path = path
  @version = MultiRepo::VERSION
end

Instance Attribute Details

#versionObject

Returns the value of attribute version.



13
14
15
# File 'lib/multirepo/files/meta-file.rb', line 13

def version
  @version
end

Instance Method Details

#encode_with(coder) ⇒ Object



32
33
34
# File 'lib/multirepo/files/meta-file.rb', line 32

def encode_with(coder)
  coder["version"] = @version
end

#ensure_access(file, error_message, &check) ⇒ Object



47
48
49
# File 'lib/multirepo/files/meta-file.rb', line 47

def ensure_access(file, error_message, &check)
  fail MultiRepoException, error_message if File.exists?(file) && !check.call(File.stat(file))
end

#exists?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/multirepo/files/meta-file.rb', line 28

def exists?
  File.exist?(file)
end

#fileObject



20
21
22
# File 'lib/multirepo/files/meta-file.rb', line 20

def file
  File.join(@path, FILENAME)
end

#filenameObject



24
25
26
# File 'lib/multirepo/files/meta-file.rb', line 24

def filename
  FILENAME
end

#loadObject



36
37
38
39
# File 'lib/multirepo/files/meta-file.rb', line 36

def load
  ensure_access(file, "Can't read meta file (permissions)") { |stat| stat.readable? }
  Psych.load(File.read(file))
end

#updateObject



41
42
43
44
45
# File 'lib/multirepo/files/meta-file.rb', line 41

def update
  ensure_access(file, "Can't write meta file (permissions)") { |stat| stat.writable? }
  content = Psych.dump(self)
  return update_internal(file, content)
end