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
30
31
# File 'lib/sys/proc/version.rb', line 25

def initialize(file_name = self.class.file_name)
  @file_name = file_name.freeze

  self.load_file
      .map { |k, v| self.attr_set(k, v) }
      .yield_self { |loaded| @data_loaded = loaded.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)


67
68
69
# File 'lib/sys/proc/version.rb', line 67

def file_name
  Pathname.new(__dir__).join('version.yml')
end

Instance Method Details

#to_hHash

Returns:

  • (Hash)


51
52
53
# File 'lib/sys/proc/version.rb', line 51

def to_h
  data_loaded.clone.freeze
end

#to_pathString

Return the path as a String.



59
60
61
# File 'lib/sys/proc/version.rb', line 59

def to_path
  file_name.to_s
end

#to_sString

Returns:

  • (String)


46
47
48
# File 'lib/sys/proc/version.rb', line 46

def to_s
  [major, minor, patch].join('.')
end

#valid?Boolean

Denote version has enough (mninimal) attributes defined.

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
# File 'lib/sys/proc/version.rb', line 36

def valid?
  ![:major, :minor, :patch]
    .map { |method| public_send(method) }
    .map { |v| v.to_s.empty? ? nil : v }
    .include?(nil)
rescue NameError
  false
end