Class: FlexmlsGems::VersionHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/flexmls_gems/version_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pwd = Dir.pwd) ⇒ VersionHelper

Returns a new instance of VersionHelper.



4
5
6
7
# File 'lib/flexmls_gems/version_helper.rb', line 4

def initialize(pwd=Dir.pwd)
  @pwd = pwd
  reset
end

Instance Attribute Details

#buildObject (readonly)

Returns the value of attribute build.



9
10
11
# File 'lib/flexmls_gems/version_helper.rb', line 9

def build
  @build
end

#majorObject (readonly)

Returns the value of attribute major.



9
10
11
# File 'lib/flexmls_gems/version_helper.rb', line 9

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



9
10
11
# File 'lib/flexmls_gems/version_helper.rb', line 9

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



9
10
11
# File 'lib/flexmls_gems/version_helper.rb', line 9

def patch
  @patch
end

Instance Method Details

#bump_build(tag = "pre") ⇒ Object



49
50
51
52
# File 'lib/flexmls_gems/version_helper.rb', line 49

def bump_build(tag="pre")
  @build = tag
  self
end

#bump_majorObject



28
29
30
31
32
33
34
# File 'lib/flexmls_gems/version_helper.rb', line 28

def bump_major
  @major += 1
  @minor = 0
  @patch = 0
  @build = nil
  self
end

#bump_minorObject



36
37
38
39
40
41
# File 'lib/flexmls_gems/version_helper.rb', line 36

def bump_minor
  @minor += 1
  @patch = 0
  @build = nil
  self
end

#bump_patchObject



43
44
45
46
47
# File 'lib/flexmls_gems/version_helper.rb', line 43

def bump_patch
  @patch += 1
  @build = nil
  self
end

#loadObject



11
12
13
14
15
# File 'lib/flexmls_gems/version_helper.rb', line 11

def load
  parse(File.read(path))
rescue
  reset
end

#parse(string) ⇒ Object



17
18
19
20
21
22
# File 'lib/flexmls_gems/version_helper.rb', line 17

def parse(string)
  version_string = string.chomp
  if version_string =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
    reset($1.to_i, $2.to_i, $3.to_i, $4)
  end
end

#pathObject



24
25
26
# File 'lib/flexmls_gems/version_helper.rb', line 24

def path
  File.join(@pwd,'VERSION')
end

#reset(major = 0, minor = 0, patch = 0, build = nil) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/flexmls_gems/version_helper.rb', line 54

def reset(major=0, minor=0, patch=0, build=nil)
  @major = major
  @minor = minor
  @patch = patch
  @build = build
  self
end

#saveObject



66
67
68
# File 'lib/flexmls_gems/version_helper.rb', line 66

def save
  File.open(path,'w') { |f| f.write to_s }
end

#to_sObject



62
63
64
# File 'lib/flexmls_gems/version_helper.rb', line 62

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