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.



22
23
24
# File 'lib/puppet_blacksmith/modulefile.rb', line 22

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

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



20
21
22
# File 'lib/puppet_blacksmith/modulefile.rb', line 20

def path
  @path
end

Instance Method Details

#bump!Object



42
43
44
45
46
47
48
# File 'lib/puppet_blacksmith/modulefile.rb', line 42

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:



54
55
56
57
58
# File 'lib/puppet_blacksmith/modulefile.rb', line 54

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



26
27
28
29
30
31
32
33
# File 'lib/puppet_blacksmith/modulefile.rb', line 26

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

#nameObject



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

def name
  .name
end

#replace_version(text, version) ⇒ Object



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

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

#versionObject



38
39
40
# File 'lib/puppet_blacksmith/modulefile.rb', line 38

def version
  .version
end