Class: Ore::Versions::VersionFile

Inherits:
Version
  • Object
show all
Defined in:
lib/ore/versions/version_file.rb

Overview

Represents a version loaded from a VERSION file.

Constant Summary collapse

@@files =

Common VERSION file-names.

%w[VERSION VERSION.yml]

Instance Attribute Summary

Attributes inherited from Version

#build, #major, #minor, #patch

Class Method Summary collapse

Methods inherited from Version

#initialize, parse

Constructor Details

This class inherits a constructor from Ore::Versions::Version

Class Method Details

.find(project) ⇒ VersionFile?

Finds the VERSION file.

Parameters:

  • project (Project)

    The Ore project.

Returns:

  • (VersionFile, nil)

    The version file of the project.



25
26
27
28
29
30
31
# File 'lib/ore/versions/version_file.rb', line 25

def self.find(project)
  @@files.each do |name|
    return load(project.path(name)) if project.file?(name)
  end

  return nil
end

.load(path) ⇒ VersionFile

Loads the version file of the project.

Parameters:

  • path (String)

    The path to the version file.

Returns:

Raises:

  • (InvalidVersion)

    The VERSION file must contain either a Hash or a String.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ore/versions/version_file.rb', line 45

def self.load(path)
  data = YAML.load_file(path)

  case data
  when Hash
    self.new(
      (data[:major] || data['major']),
      (data[:minor] || data['minor']),
      (data[:patch] || data['patch']),
      (data[:build] || data['build'])
    )
  when String
    self.parse(data)
  else
    file = File.basename(@path)
    raise(InvalidVersion,"invalid version data in #{file.dump}")
  end
end