class Sys::Proc::Version
Describe version using a YAML file.
Attributes
data_loaded[R]
@return [Hash]
file_name[R]
Get filepath used to parse version (YAML file).
@return [Pathname|String]
Public Class Methods
file_name()
click to toggle source
Get default filename.
@return [Pathname]
# File lib/sys/proc/version.rb, line 65 def file_name Pathname.new(__dir__).join('version.yml') end
new(file_name = self.class.file_name)
click to toggle source
@param [String] file_name
# 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
Public Instance Methods
to_h()
click to toggle source
@return [Hash]
# File lib/sys/proc/version.rb, line 49 def to_h data_loaded.clone.freeze end
to_path()
click to toggle source
Return the path as a String.
@see ruby-doc.org/stdlib-2.5.0/libdoc/pathname/rdoc/Pathname.html#method-i-to_path @return [String]
# File lib/sys/proc/version.rb, line 57 def to_path file_name.to_s end
to_s()
click to toggle source
@return [String]
# File lib/sys/proc/version.rb, line 44 def to_s [major, minor, patch].join('.') end
valid?()
click to toggle source
Denote version has enough (mninimal) attributes defined.
@return [Boolean]
# 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
Protected Instance Methods
attr_set(attr_name, attr_value)
click to toggle source
Define attribute (as “ro“ attr) and set value.
@param [String|Symbol] attr_name @param [Object] attr_value @return [Array]
# File lib/sys/proc/version.rb, line 87 def attr_set(attr_name, attr_value) inflector = Dry::Inflector.new attr_name = inflector.underscore(attr_name.to_s) self.singleton_class.class_eval do attr_accessor attr_name protected "#{attr_name}=" end self.__send__("#{attr_name}=", attr_value.freeze) [attr_name, attr_value.freeze].freeze end
load_file()
click to toggle source
@return [Hash]
# File lib/sys/proc/version.rb, line 76 def load_file YAML.load_file(file_name) || {} rescue Errno::ENOENT {} end