Class: Sys::Proc::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/sys/proc/version.rb

Overview

Describe version using a YAML file.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name = self.class.file_name) ⇒ Version

Returns a new instance of Version.

Parameters:

  • file_name (String) (defaults to: self.class.file_name)


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_namePathname|String (readonly)

Get filepath used to parse version (YAML file).

Returns:

  • (Pathname|String)


22
23
24
# File 'lib/sys/proc/version.rb', line 22

def file_name
  @file_name
end

Class Method Details

.file_namePathname

Get default filename.

Returns:

  • (Pathname)


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_hHash

Returns:

  • (Hash)


49
50
51
# File 'lib/sys/proc/version.rb', line 49

def to_h
  data_loaded.clone.freeze
end

#to_pathString

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_sString

Returns:

  • (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.

Returns:

  • (Boolean)


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