class Blacksmith::Modulefile

Constants

FILES

Attributes

path[R]

Public Class Methods

new(path = nil) click to toggle source
# File lib/puppet_blacksmith/modulefile.rb, line 10
def initialize(path = nil)
  @path = path.nil? ? FILES.find {|f| File.exists? f} : path
  raise Blacksmith::Error, "Unable to find any of #{FILES}" unless @path
end

Public Instance Methods

author() click to toggle source
# File lib/puppet_blacksmith/modulefile.rb, line 27
def author
  metadata['author'] || namespace
end
bump!(level = :patch) click to toggle source
# File lib/puppet_blacksmith/modulefile.rb, line 41
def bump!(level = :patch)
  new_version = increase_version(version, level)
  bump_to_version!(new_version)
end
bump_dep!(module_name, version) click to toggle source
# File lib/puppet_blacksmith/modulefile.rb, line 50
def bump_dep!(module_name, version)
  text = File.read(path)
  text = replace_dependency_version(text, module_name, version)
  File.open(path, "w") {|file| file.puts text}
end
bump_to_version!(new_version) click to toggle source
# File lib/puppet_blacksmith/modulefile.rb, line 34
def bump_to_version!(new_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, level = :patch) click to toggle source
# File lib/puppet_blacksmith/modulefile.rb, line 62
def increase_version(version, level = :patch)
  v = VersionHelper::Version.new(version)
  v.send("#{level}!").to_s
end
metadata() click to toggle source
# File lib/puppet_blacksmith/modulefile.rb, line 15
def metadata
  @metadata = JSON.parse(File.read(path)) unless @metadata
  @metadata
end
name() click to toggle source

name in metadata.json is author-modulename

# File lib/puppet_blacksmith/modulefile.rb, line 21
def name
  metadata['name'].split('-',2)[1]
end
namespace() click to toggle source
# File lib/puppet_blacksmith/modulefile.rb, line 24
def namespace
  metadata['name'].split('-',2)[0]
end
replace_dependency_version(text, module_name, version) click to toggle source
# File lib/puppet_blacksmith/modulefile.rb, line 67
def replace_dependency_version(text, module_name, version)
  module_name = module_name.sub(/\//, '-')
  json = JSON.parse(text)
  new_dep_list = []
  json['dependencies'].each do |dep|
    dep['version_requirement'] = version if dep['name'] == module_name
    new_dep_list << dep
  end
  json['dependencies'] = new_dep_list
  JSON.pretty_generate(json)
end
replace_version(text, version) click to toggle source
# File lib/puppet_blacksmith/modulefile.rb, line 56
def replace_version(text, version)
  json = JSON.parse(text)
  json['version'] = version
  JSON.pretty_generate(json)
end
version() click to toggle source
# File lib/puppet_blacksmith/modulefile.rb, line 30
def version
  metadata['version']
end