Class: Epuber::Lockfile
- Inherits:
-
Object
- Object
- Epuber::Lockfile
- Defined in:
- lib/epuber/lockfile.rb
Instance Attribute Summary collapse
-
#defined_from_file ⇒ Object
Returns the value of attribute defined_from_file.
Class Method Summary collapse
-
.from_file(file_path) {|inst| ... } ⇒ self
Load existing lockfile from given path, or create new one.
Instance Method Summary collapse
- #bade_version ⇒ Epuber::Version
- #bade_version=(new_version) ⇒ Object
- #epuber_version ⇒ Epuber::Version
- #epuber_version=(new_version) ⇒ Object
-
#initialize(data = {}) ⇒ Lockfile
constructor
A new instance of Lockfile.
-
#write_to_file ⇒ Object
Nil.
Constructor Details
#initialize(data = {}) ⇒ Lockfile
Returns a new instance of Lockfile.
12 13 14 |
# File 'lib/epuber/lockfile.rb', line 12 def initialize(data = {}) @internal_data = data end |
Instance Attribute Details
#defined_from_file ⇒ Object
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.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/epuber/lockfile.rb', line 20 def self.from_file(file_path) if File.exist?(file_path) hash = YAML.safe_load(File.read(file_path)) else hash = {} end # backward compatibility for version 0.5 and older if hash.include?('version') hash['epuber_version'] = hash.delete('version') end inst = self.new(hash) inst.defined_from_file = file_path yield inst if hash.empty? && block_given? inst end |
Instance Method Details
#bade_version ⇒ Epuber::Version
60 61 62 63 64 |
# File 'lib/epuber/lockfile.rb', line 60 def bade_version value = @internal_data['bade_version'] value = Version.new(value) unless value.nil? value end |
#bade_version=(new_version) ⇒ Object
68 69 70 |
# File 'lib/epuber/lockfile.rb', line 68 def bade_version=(new_version) @internal_data['bade_version'] = new_version end |
#epuber_version ⇒ Epuber::Version
48 49 50 |
# File 'lib/epuber/lockfile.rb', line 48 def epuber_version Version.new(@internal_data['epuber_version']) end |
#epuber_version=(new_version) ⇒ Object
54 55 56 |
# File 'lib/epuber/lockfile.rb', line 54 def epuber_version=(new_version) @internal_data['epuber_version'] = new_version.to_s end |
#write_to_file ⇒ Object
Returns nil.
40 41 42 43 44 |
# File 'lib/epuber/lockfile.rb', line 40 def write_to_file return if defined_from_file.nil? File.write(defined_from_file, @internal_data.to_yaml) end |