Class: StiDeploy::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/sti_deploy/version.rb,
lib/sti_deploy/version/hotfix.rb,
lib/sti_deploy/version/release.rb,
lib/sti_deploy/version/pre_release.rb,
lib/sti_deploy/version/version_bumper.rb,
lib/sti_deploy/version/release_candidate.rb

Defined Under Namespace

Classes: Hotfix, PreRelease, Release, ReleaseCandidate, VersionBumper

Constant Summary collapse

FULL_VERSION_REGEX =
/[\d]+.[\d]+.[\d]+(rc[\d]+)?(pre[\d]+)?/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ Version

Returns a new instance of Version.



43
44
45
46
47
48
49
# File 'lib/sti_deploy/version.rb', line 43

def initialize(version)
  @major, @minor, @hotfix = version[/[\d]+.[\d]+.[\d]+/].split('.')
                              .map(&:to_i)
  self.rc = version[/rc[\d]+/].to_s.tr('rc', '').to_i
  self.pre = version[/pre[\d]+/].to_s.tr('pre', '').to_i
  @old = to_s
end

Instance Attribute Details

#hotfixObject

Returns the value of attribute hotfix.



5
6
7
# File 'lib/sti_deploy/version.rb', line 5

def hotfix
  @hotfix
end

#majorObject

Returns the value of attribute major.



5
6
7
# File 'lib/sti_deploy/version.rb', line 5

def major
  @major
end

#minorObject

Returns the value of attribute minor.



5
6
7
# File 'lib/sti_deploy/version.rb', line 5

def minor
  @minor
end

#oldObject (readonly)

Returns the value of attribute old.



6
7
8
# File 'lib/sti_deploy/version.rb', line 6

def old
  @old
end

#preObject

Returns the value of attribute pre.



5
6
7
# File 'lib/sti_deploy/version.rb', line 5

def pre
  @pre
end

#rcObject

Returns the value of attribute rc.



5
6
7
# File 'lib/sti_deploy/version.rb', line 5

def rc
  @rc
end

Class Method Details

.load_versionObject



11
12
13
14
15
16
17
# File 'lib/sti_deploy/version.rb', line 11

def load_version
  validate_version_file
  version = read_current_version
  validate_version(version)
  Messages.puts('version.detected', version: version, color: :green)
  version
end

Instance Method Details

#bump(deploy_type) ⇒ Object



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

def bump(deploy_type)
  VersionBumper.from_deploy_type(deploy_type, self).bump
end

#to_sObject



61
62
63
64
65
66
# File 'lib/sti_deploy/version.rb', line 61

def to_s
  base = "#{major}.#{minor}.#{hotfix}"
  base += "rc#{rc}" if rc > 0
  base += "pre#{pre}" if pre > 0
  base
end

#update_file!Object



55
56
57
58
59
# File 'lib/sti_deploy/version.rb', line 55

def update_file!
  version_file = File.read(Configuration.version_path)
  new_version = version_file.gsub(FULL_VERSION_REGEX, to_s)
  File.open(Configuration.version_path, 'w') { |f| f.puts new_version }
end