Class: Blacksmith::Modulefile

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_blacksmith/modulefile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = "Modulefile") ⇒ Modulefile

Returns a new instance of Modulefile.



18
19
20
# File 'lib/puppet_blacksmith/modulefile.rb', line 18

def initialize(path = "Modulefile")
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



16
17
18
# File 'lib/puppet_blacksmith/modulefile.rb', line 16

def path
  @path
end

Instance Method Details

#bump!Object



38
39
40
41
42
43
44
# File 'lib/puppet_blacksmith/modulefile.rb', line 38

def bump!
  new_version = increase_version(version)
  text = File.read(path)
  text = replace_version(text, new_version)
  File.open(path, "w") {|file| file.puts text}
  new_version
end

#increase_version(version) ⇒ Object

Raises:



50
51
52
53
54
# File 'lib/puppet_blacksmith/modulefile.rb', line 50

def increase_version(version)
  v = Gem::Version.new("#{version}.0")
  raise Blacksmith::Error, "Unable to increase prerelease version #{version}" if v.prerelease?
  v.bump.to_s
end

#metadataObject



22
23
24
25
26
27
28
29
# File 'lib/puppet_blacksmith/modulefile.rb', line 22

def 
  unless 
     = Puppet::ModuleTool::.new
    Puppet::ModuleTool::ModulefileReader.evaluate(, path)
     = 
  end
  
end

#nameObject



31
32
33
# File 'lib/puppet_blacksmith/modulefile.rb', line 31

def name
  .name
end

#replace_version(text, version) ⇒ Object



46
47
48
# File 'lib/puppet_blacksmith/modulefile.rb', line 46

def replace_version(text, version)
  text.gsub(/\nversion[ ]+['"].*['"]/, "\nversion '#{version}'")
end

#versionObject



34
35
36
# File 'lib/puppet_blacksmith/modulefile.rb', line 34

def version
  .version
end