Class: Sys::Proc::Version
- Inherits:
-
Object
- Object
- Sys::Proc::Version
- Defined in:
- lib/sys/proc/version.rb
Overview
Describe version using a YAML file.
Instance Attribute Summary collapse
-
#file_name ⇒ Pathname|String
readonly
Get filepath used to parse version (YAML file).
Class Method Summary collapse
-
.file_name ⇒ Pathname
Get default filename.
Instance Method Summary collapse
-
#initialize(file_name = self.class.file_name) ⇒ Version
constructor
A new instance of Version.
- #to_h ⇒ Hash
-
#to_path ⇒ String
Return the path as a String.
- #to_s ⇒ String
-
#valid? ⇒ Boolean
Denote version has enough (mninimal) attributes defined.
Constructor Details
#initialize(file_name = self.class.file_name) ⇒ Version
Returns a new instance of Version.
25 26 27 28 29 |
# File 'lib/sys/proc/version.rb', line 25 def initialize(file_name = self.class.file_name) @file_name = file_name.freeze @data_loaded = self.load_file .map { |k, v| self.attr_set(k, v) }.to_h end |
Instance Attribute Details
#file_name ⇒ Pathname|String (readonly)
Get filepath used to parse version (YAML file).
22 23 24 |
# File 'lib/sys/proc/version.rb', line 22 def file_name @file_name end |
Class Method Details
.file_name ⇒ Pathname
Get default filename.
65 66 67 |
# File 'lib/sys/proc/version.rb', line 65 def file_name Pathname.new(__dir__).join('version.yml') end |
Instance Method Details
#to_h ⇒ Hash
49 50 51 |
# File 'lib/sys/proc/version.rb', line 49 def to_h data_loaded.clone.freeze end |
#to_path ⇒ String
Return the path as a String.
57 58 59 |
# File 'lib/sys/proc/version.rb', line 57 def to_path file_name.to_s end |
#to_s ⇒ String
44 45 46 |
# File 'lib/sys/proc/version.rb', line 44 def to_s [major, minor, patch].join('.') end |
#valid? ⇒ Boolean
Denote version has enough (mninimal) attributes defined.
34 35 36 37 38 39 40 41 |
# File 'lib/sys/proc/version.rb', line 34 def valid? ![:major, :minor, :patch] .map { |method| public_send(method) } .map { |v| v.to_s.empty? ? nil : v } .include?(nil) rescue NameError false end |