Class: Epuber::Lockfile

Inherits:
Object
  • Object
show all
Defined in:
lib/epuber/lockfile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Lockfile

Returns a new instance of Lockfile.

Parameters:

  • data (Hash) (defaults to: {})


12
13
14
# File 'lib/epuber/lockfile.rb', line 12

def initialize(data = {})
  @internal_data = data
end

Instance Attribute Details

#defined_from_fileObject

Returns the value of attribute defined_from_file.



8
9
10
# File 'lib/epuber/lockfile.rb', line 8

def defined_from_file
  @defined_from_file
end

Class Method Details

.from_file(file_path) {|inst| ... } ⇒ self

Load existing lockfile from given path, or create new one. You can define default attributes in block.

Yields:

  • (inst)

Returns:

  • (self)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/epuber/lockfile.rb', line 20

def self.from_file(file_path)
  hash = if File.exist?(file_path)
           YAML.safe_load(File.read(file_path))
         else
           {}
         end

  # backward compatibility for version 0.5 and older
  hash['epuber_version'] = hash.delete('version') if hash.include?('version')

  inst = new(hash)
  inst.defined_from_file = file_path
  yield inst if hash.empty? && block_given?
  inst
end

Instance Method Details

#bade_versionEpuber::Version

Returns:



58
59
60
61
62
# File 'lib/epuber/lockfile.rb', line 58

def bade_version
  value = @internal_data['bade_version']
  value = Version.new(value) unless value.nil?
  value
end

#bade_version=(new_version) ⇒ Object

Parameters:



66
67
68
# File 'lib/epuber/lockfile.rb', line 66

def bade_version=(new_version)
  @internal_data['bade_version'] = new_version
end

#epuber_versionEpuber::Version

Returns:



46
47
48
# File 'lib/epuber/lockfile.rb', line 46

def epuber_version
  Version.new(@internal_data['epuber_version'])
end

#epuber_version=(new_version) ⇒ Object

Parameters:



52
53
54
# File 'lib/epuber/lockfile.rb', line 52

def epuber_version=(new_version)
  @internal_data['epuber_version'] = new_version.to_s
end

#write_to_fileObject

Returns nil.

Returns:

  • nil



38
39
40
41
42
# File 'lib/epuber/lockfile.rb', line 38

def write_to_file
  return if defined_from_file.nil?

  File.write(defined_from_file, @internal_data.to_yaml)
end