Class: StiDeploy::Version

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

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.



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

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
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

#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



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

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



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

def bump(deploy_type)
  old = to_s
  send("bump_#{deploy_type}")
  Messages.puts('version.increment', old: old, new: to_s, color: :green)
  to_s
end

#to_sObject



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

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

#update_file!Object



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

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