class Puppetfile

Constants

BUMP_TYPES

Attributes

base_path[RW]
data[RW]
modules[RW]
path[RW]
puppetfile[RW]
puppetmodule[RW]

Public Class Methods

from_string(s) click to toggle source
# File lib/release_manager/puppetfile.rb, line 78
def self.from_string(s)
  instance = new
  instance.data = s
  instance
end
new(puppetfile = 'Puppetfile') click to toggle source

@param [String] puppetfile - the path to the puppetfile

# File lib/release_manager/puppetfile.rb, line 19
def initialize(puppetfile = 'Puppetfile')
  @puppetfile = puppetfile
  @puppetmodule = PuppetModule.new(base_path)
end
to_puppetfile(json_data) click to toggle source
# File lib/release_manager/puppetfile.rb, line 165
def self.to_puppetfile(json_data)
  obj = JSON.parse(json_data)
  mods = obj.collect do |name, metadata|
    name = "mod '#{name}',"
    data = metadata.sort.map { |k, v| ":#{k} => '#{v}'" }.join(",\n\  ")
    "#{name}\n  #{data}\n"
  end.join("\n")
  mods
end

Public Instance Methods

add_module(name, metadata) click to toggle source
# File lib/release_manager/puppetfile.rb, line 49
def add_module(name, metadata)
  modules[name] = ControlMod.new(name, metadata)
end
bump(mod_name, type = 'patch') click to toggle source
# File lib/release_manager/puppetfile.rb, line 133
def bump(mod_name, type = 'patch')
  raise "Invalid type, must be one of #{BUMP_TYPES}" unless BUMP_TYPES.include?(type)
  mod = find_mod(mod_name)
  find_mod(mod_name).send("bump_#{type}_version")
end
commit(message, remote = false) click to toggle source
# File lib/release_manager/puppetfile.rb, line 32
def commit(message, remote = false)
  message = "[ReleaseManager] - #{message}"
  if remote
    actions = [{
       action: 'update',
       file_path: puppetfile.split(repo.workdir).last,
       content: to_s
    }]
    obj = vcs_create_commit(source, 'master', message, actions)
    obj.id if obj
  else
    write_to_file
    add_file(puppetfile)
    create_commit(message)
  end
end
diff(a,b) click to toggle source
# File lib/release_manager/puppetfile.rb, line 147
def diff(a,b)
  FileUtils.compare_stream(a,b)
end
find_mod(name) click to toggle source

@param [String] name - the name of the mod you wish to find in the puppetfile @return ControlMod - a ControlMod object

# File lib/release_manager/puppetfile.rb, line 98
def find_mod(name)
  mod_name = name.strip.downcase
  mod = modules[mod_name] || modules.find{ |module_name, mod| mod.repo =~ /#{mod_name}/i }
  raise InvalidModuleNameException.new("Invalid module name #{name}, cannot locate in Puppetfile") unless mod
  # since find returns an array we need to grab the element ouf of the array first
  return mod.last if mod.instance_of?(Array)
  mod
end
find_mods(names) click to toggle source

@param Array names - find all mods with the following names @return Hash[String, ControlMod] - returns the pupppet modules in a hash

# File lib/release_manager/puppetfile.rb, line 86
def find_mods(names)
  mods = {}
  return mods if names.nil?
  names.each do | mod_name |
    m = find_mod(mod_name)
    mods[m.name] = m
  end
  mods
end
forge(name, *args) click to toggle source
# File lib/release_manager/puppetfile.rb, line 179
def forge(name, *args)
  # skip this for now
end
mod(name, *args) click to toggle source
# File lib/release_manager/puppetfile.rb, line 175
def mod(name, *args)
  @modules[name] = ControlMod.new(name, args.flatten.first)
end
mod_exists?(name) click to toggle source

@param [String] name - the name of the mod you wish to find in the puppetfile @return [Boolean] - true if the module is found

# File lib/release_manager/puppetfile.rb, line 109
def mod_exists?(name)
  begin
    !!find_mod(name)
  rescue InvalidModuleNameException
    false
  end
end
push(remote, branch, force = false, tags = true) click to toggle source

@param remote [String] - the remote name @param branch [String] - the branch to push @param force [Boolean] - force push , defaults to false @pram tags [Boolean] - push tags, defaults to true

# File lib/release_manager/puppetfile.rb, line 57
def push(remote, branch, force = false, tags = true)
  push_branch(remote, branch, force)
  push_tags(remote) if tags
end
source() click to toggle source
# File lib/release_manager/puppetfile.rb, line 24
def source
  puppetmodule.source
end
to_json(pretty = false) click to toggle source
# File lib/release_manager/puppetfile.rb, line 139
def to_json(pretty = false)
  if pretty
    JSON.pretty_generate(modules)
  else
    modules.to_json
  end
end
to_s() click to toggle source
# File lib/release_manager/puppetfile.rb, line 161
def to_s
  modules.sort.collect {|n, mod| mod.to_s }.join("\n\n")
end
write_source(mod_name, src, branch = nil) click to toggle source

@param [String] mod_name - the module name found in the puppetfile @param [String] src - the git url to the source @option [String] branch - the branch name to pin to if provided @return [ControlMod]

# File lib/release_manager/puppetfile.rb, line 126
def write_source(mod_name, src, branch = nil)
  mod = find_mod(mod_name)
  mod.pin_url(src)
  mod.pin_branch(branch) if branch
  mod
end
write_to_file() click to toggle source

@return [Boolean] - true if writing to file occurred, false otherwise

# File lib/release_manager/puppetfile.rb, line 152
def write_to_file
  contents = to_s
  a = StringIO.new(contents)
  b = File.new(puppetfile)
  # do not write to the file if nothing changed
  return false if FileUtils.compare_stream(a,b)
  File.write(puppetfile, to_s)
end
write_version(mod_name, version) click to toggle source
# File lib/release_manager/puppetfile.rb, line 117
def write_version(mod_name, version)
  mod = find_mod(mod_name)
  mod.pin_version(version)
end