Class: Bueller::VersionHelper

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

Defined Under Namespace

Classes: MalformattedVersion, VersionMissing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gemspec_helper) ⇒ VersionHelper

Returns a new instance of VersionHelper.



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

def initialize(gemspec_helper)
  self.gemspec_helper = gemspec_helper
  parse_version
end

Instance Attribute Details

#buildObject (readonly)

Returns the value of attribute build.



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

def build
  @build
end

#gemspec_helperObject

Returns the value of attribute gemspec_helper.



8
9
10
# File 'lib/bueller/version_helper.rb', line 8

def gemspec_helper
  @gemspec_helper
end

#majorObject (readonly)

Returns the value of attribute major.



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

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



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

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



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

def patch
  @patch
end

Instance Method Details

#bump_majorObject



41
42
43
44
45
46
# File 'lib/bueller/version_helper.rb', line 41

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

#bump_minorObject



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

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

#bump_patchObject



54
55
56
57
# File 'lib/bueller/version_helper.rb', line 54

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

#parse_versionObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/bueller/version_helper.rb', line 24

def parse_version
  if version_source =~ /VERSION[^\d]+(\d+)\.(\d+)\.(\d+)(\.([^'"]*))?/
    @major = $1.to_i
    @minor = $2.to_i
    @patch = $3.to_i
    @build = $5
  else
    raise VersionMissing, "lib/#{gemspec_helper.project_name}/version.rb doesn't contain a version string"
  end
end

#pathObject



16
17
18
# File 'lib/bueller/version_helper.rb', line 16

def path
  File.join(gemspec_helper.base_dir, 'lib', gemspec_helper.project_name, 'version.rb')
end

#to_sObject



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

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

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



59
60
61
62
63
64
# File 'lib/bueller/version_helper.rb', line 59

def update_to(major, minor, patch, build=nil)
  @major = major
  @minor = minor
  @patch = patch
  @build = build
end

#version_sourceObject



20
21
22
# File 'lib/bueller/version_helper.rb', line 20

def version_source
  @version_source ||= File.read path
end

#write_versionObject



35
36
37
38
39
# File 'lib/bueller/version_helper.rb', line 35

def write_version
  version_source.sub! /VERSION\s*=.*/, %Q{VERSION = "#{to_s}"}
  File.open(path, 'w') { |f| f.puts version_source }
  parse_version
end