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.



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

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

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#bump!Object



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

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:



52
53
54
55
56
# File 'lib/puppet_blacksmith/modulefile.rb', line 52

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



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

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

#nameObject



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

def name
  .name
end

#replace_version(text, version) ⇒ Object



48
49
50
# File 'lib/puppet_blacksmith/modulefile.rb', line 48

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

#versionObject



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

def version
  .version
end