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 |
# 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_version ⇒ Epuber::Version
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
66 67 68 |
# File 'lib/epuber/lockfile.rb', line 66 def bade_version=(new_version) @internal_data['bade_version'] = new_version end |
#epuber_version ⇒ Epuber::Version
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
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_file ⇒ Object
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 |