Class: AlpacaBuildTool::Version
- Inherits:
-
Object
- Object
- AlpacaBuildTool::Version
- Defined in:
- lib/alpacabuildtool/versioning/version.rb
Overview
Version contains semantic version and methods for updating it
Constant Summary collapse
- PRE_RELEASE =
PreRelease acceptable tags
%w(alpha beta rc)
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
-
#special ⇒ Object
readonly
Returns the value of attribute special.
Instance Method Summary collapse
-
#increase(dimension) ⇒ Object
Increase version following semantic version rules.
-
#initialize(hash) ⇒ Version
constructor
Creates new instance.
-
#make_prerelease ⇒ Object
Set version to prerelease by adding ‘alpha’ to special.
-
#metadata? ⇒ Boolean
Returns true if #metadata isn’t empty.
-
#prerelease? ⇒ Boolean
Returns true if #special isn’t empty.
-
#release ⇒ Object
Clear special and metadata so version become higher and not prerelease.
-
#to_s(format = 'v%M.%m.%p%s%d') ⇒ Object
Formatting version to string.
-
#to_yaml ⇒ Object
Returns yaml representation that can be stored to .semver file.
Constructor Details
#initialize(hash) ⇒ Version
Creates new instance
hash-
Hash with version data:
:file - file with path to .semver file :major - major version :minor - minor version :patch - patch version :special - special version :metadata - metadata
30 31 32 33 34 35 36 37 38 |
# File 'lib/alpacabuildtool/versioning/version.rb', line 30 def initialize(hash) @file = hash.fetch(:file) { fail InvalidFile } @major = hash.fetch(:major) { fail InvalidFile } @minor = hash.fetch(:minor) { fail InvalidFile } @patch = hash.fetch(:patch) { fail InvalidFile } @special = hash.fetch(:special) { fail InvalidFile } = hash.fetch(:metadata) { fail InvalidFile } validate end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
7 8 9 |
# File 'lib/alpacabuildtool/versioning/version.rb', line 7 def file @file end |
#major ⇒ Object (readonly)
Returns the value of attribute major.
7 8 9 |
# File 'lib/alpacabuildtool/versioning/version.rb', line 7 def major @major end |
#metadata ⇒ Object
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/alpacabuildtool/versioning/version.rb', line 7 def end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
7 8 9 |
# File 'lib/alpacabuildtool/versioning/version.rb', line 7 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
7 8 9 |
# File 'lib/alpacabuildtool/versioning/version.rb', line 7 def patch @patch end |
#special ⇒ Object (readonly)
Returns the value of attribute special.
7 8 9 |
# File 'lib/alpacabuildtool/versioning/version.rb', line 7 def special @special end |
Instance Method Details
#increase(dimension) ⇒ Object
Increase version following semantic version rules
dimension-
one of the dimensions:
:major # increase major and reset lower versions
:minor # increase minor and reset lower versions
:patch # increase patch and reset lower versions
:prerelease # increase prerelease tag
96 97 98 99 100 101 102 103 104 |
# File 'lib/alpacabuildtool/versioning/version.rb', line 96 def increase(dimension) case dimension when :major then increase_major when :minor then increase_minor when :patch then increase_patch when :prerelease then increase_prerelease else fail WrongDimension end end |
#make_prerelease ⇒ Object
Set version to prerelease by adding ‘alpha’ to special
108 109 110 111 |
# File 'lib/alpacabuildtool/versioning/version.rb', line 108 def make_prerelease fail AlreadyPreRelease if prerelease? @special = PRE_RELEASE.first end |
#metadata? ⇒ Boolean
Returns true if #metadata isn’t empty. Otherwise, false.
84 85 86 |
# File 'lib/alpacabuildtool/versioning/version.rb', line 84 def !.nil? && !.empty? end |
#prerelease? ⇒ Boolean
Returns true if #special isn’t empty. Otherwise, false.
78 79 80 |
# File 'lib/alpacabuildtool/versioning/version.rb', line 78 def prerelease? !@special.nil? && !@special.empty? end |
#release ⇒ Object
Clear special and metadata so version become higher and not prerelease
115 116 117 118 119 |
# File 'lib/alpacabuildtool/versioning/version.rb', line 115 def release fail AlreadyRelease unless prerelease? @special = '' = '' end |
#to_s(format = 'v%M.%m.%p%s%d') ⇒ Object
Formatting version to string
format-
format of version representation
%M - Major %m - Minor %p - Patch %s - Special (adds ‘-’) %d - Metadata (adds ‘+’)
v.inspect
# => #<AlpacaBuildTool::Version:0x000000031aca90
# @file="d:/Learning/Ruby/alpaca/.semver",
# @major=1,
# @minor=2,
# @patch=3,
# @special="rc",
# @metadata="03fb4">
v.format 'v%M.%m.%p%s%d'
# => "v1.2.3-rc+03fb4"
60 61 62 63 64 65 66 67 |
# File 'lib/alpacabuildtool/versioning/version.rb', line 60 def to_s(format = 'v%M.%m.%p%s%d') result = format.gsub '%M', @major.to_s result.gsub! '%m', @minor.to_s result.gsub! '%p', @patch.to_s result.gsub!('%s', prerelease? ? "-#{@special}" : '') result.gsub!('%d', ? "+#{@metadata}" : '') result end |
#to_yaml ⇒ Object
Returns yaml representation that can be stored to .semver file
71 72 73 74 |
# File 'lib/alpacabuildtool/versioning/version.rb', line 71 def to_yaml YAML.dump(major: @major, minor: @minor, patch: @patch, special: @special, metadata: ) end |