Class: CookbookDevelopment::VersionFile

Inherits:
Object
  • Object
show all
Defined in:
lib/cookbook/development/rake/version_tasks.rb

Direct Known Subclasses

MetadataVersion

Constant Summary collapse

VERSION_FILE =
File.join(Dir.pwd, 'VERSION')
ALT_VERSION_FILE =
File.join(Dir.pwd, 'recipes', 'VERSION')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ VersionFile

Returns a new instance of VersionFile.



33
34
35
36
# File 'lib/cookbook/development/rake/version_tasks.rb', line 33

def initialize(path)
  @path = Pathname.new(path)
  @version = @path.read
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



32
33
34
# File 'lib/cookbook/development/rake/version_tasks.rb', line 32

def path
  @path
end

#versionObject (readonly)

Returns the value of attribute version.



31
32
33
# File 'lib/cookbook/development/rake/version_tasks.rb', line 31

def version
  @version
end

Class Method Details

.in_dir(dir = Dir.pwd) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cookbook/development/rake/version_tasks.rb', line 11

def in_dir(dir = Dir.pwd)
   = File.join(Dir.pwd, 'metadata.rb')

  if File.exist? VERSION_FILE
    VersionFile.new(VERSION_FILE)
  elsif File.exist? ALT_VERSION_FILE
    # The release process relies on having a VERSION file in the root of
    # your cookbook as well as the version attribute in metadata.rb reading
    # from said VERSION file. Until https://github.com/opscode/test-kitchen/pull/212
    # is resolved we need to put the cookbooks in a place that test-kitchen
    # will copy to the VM.
    VersionFile.new(ALT_VERSION_FILE)
  elsif File.exist? 
    MetadataVersion.new()
  else
    raise 'I could not find a VERSION file or a metadata.rb'
  end
end

Instance Method Details

#bump(level) ⇒ Object



38
39
40
# File 'lib/cookbook/development/rake/version_tasks.rb', line 38

def bump(level)
  @version.to_version.bump!(level).to_s
end

#bump!(level) ⇒ Object



42
43
44
45
46
# File 'lib/cookbook/development/rake/version_tasks.rb', line 42

def bump!(level)
  @version = bump(level)
  save
  @version
end

#saveObject



52
53
54
55
56
# File 'lib/cookbook/development/rake/version_tasks.rb', line 52

def save
  @path.open('w') do |io|
    io << self
  end
end

#to_sObject



48
49
50
# File 'lib/cookbook/development/rake/version_tasks.rb', line 48

def to_s
  @version
end