Class: Jeweler::Version

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_dir) ⇒ Version

Returns a new instance of Version.



6
7
8
9
10
11
12
# File 'lib/jeweler/version.rb', line 6

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.



3
4
5
# File 'lib/jeweler/version.rb', line 3

def base_dir
  @base_dir
end

#majorObject (readonly)

Returns the value of attribute major.



4
5
6
# File 'lib/jeweler/version.rb', line 4

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



4
5
6
# File 'lib/jeweler/version.rb', line 4

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



4
5
6
# File 'lib/jeweler/version.rb', line 4

def patch
  @patch
end

Instance Method Details

#bump_majorObject



14
15
16
17
18
# File 'lib/jeweler/version.rb', line 14

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

#bump_minorObject



20
21
22
23
# File 'lib/jeweler/version.rb', line 20

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

#bump_patchObject



25
26
27
# File 'lib/jeweler/version.rb', line 25

def bump_patch
  @patch += 1
end

#refreshObject



53
54
55
# File 'lib/jeweler/version.rb', line 53

def refresh
  parse_yaml
end

#to_hashObject



45
46
47
48
49
50
51
# File 'lib/jeweler/version.rb', line 45

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

#to_sObject



41
42
43
# File 'lib/jeweler/version.rb', line 41

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

#update_to(major, minor, patch) ⇒ Object



29
30
31
32
33
# File 'lib/jeweler/version.rb', line 29

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

#writeObject



35
36
37
38
39
# File 'lib/jeweler/version.rb', line 35

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

#yaml_pathObject



57
58
59
60
61
# File 'lib/jeweler/version.rb', line 57

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