Class: Jeweler::VersionHelper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_dir) ⇒ VersionHelper

Returns a new instance of VersionHelper.



8
9
10
11
12
13
14
# File 'lib/jeweler/version_helper.rb', line 8

def initialize(base_dir)
  self.base_dir = base_dir

  if File.exists?(yaml_path)
    parse_yaml
  end
end

Instance Attribute Details

#base_dirObject

Returns the value of attribute base_dir.



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

def base_dir
  @base_dir
end

#majorObject (readonly)

Returns the value of attribute major.



6
7
8
# File 'lib/jeweler/version_helper.rb', line 6

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



6
7
8
# File 'lib/jeweler/version_helper.rb', line 6

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



6
7
8
# File 'lib/jeweler/version_helper.rb', line 6

def patch
  @patch
end

Instance Method Details

#bump_majorObject



16
17
18
19
20
# File 'lib/jeweler/version_helper.rb', line 16

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

#bump_minorObject



22
23
24
25
# File 'lib/jeweler/version_helper.rb', line 22

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

#bump_patchObject



27
28
29
# File 'lib/jeweler/version_helper.rb', line 27

def bump_patch
  @patch += 1
end

#refreshObject



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

def refresh
  parse_yaml
end

#to_hashObject



47
48
49
50
51
52
53
# File 'lib/jeweler/version_helper.rb', line 47

def to_hash
  {
    :major => major,
    :minor => minor,
    :patch => patch
  }
end

#to_sObject



43
44
45
# File 'lib/jeweler/version_helper.rb', line 43

def to_s
  "#{major}.#{minor}.#{patch}"
end

#update_to(major, minor, patch) ⇒ Object



31
32
33
34
35
# File 'lib/jeweler/version_helper.rb', line 31

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

#writeObject



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

def write
  File.open(yaml_path, 'w+') do |f|
    YAML.dump(self.to_hash, f)
  end
end

#yaml_pathObject



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

def yaml_path
  denormalized_path = File.join(@base_dir, 'VERSION.yml')
  absolute_path = File.expand_path(denormalized_path)
  absolute_path.gsub(Dir.getwd + File::SEPARATOR, '')
end