class Environmate::Environment

Attributes

name[R]

Public Class Methods

new(env_path) click to toggle source
# File lib/environmate/environment.rb, line 10
def initialize(env_path)
  @env_path = env_path
  @name     = File.basename(env_path)
  @git      = GitRepository.new(env_path)
  @install_modules_command = Environmate.configuration['install_modules_command']
end

Public Instance Methods

copy(revision) click to toggle source

This create a copy of the current repository under the specified revision name and update that environment to the specified revision.

  • revision - The revision to update the repository to

# File lib/environmate/environment.rb, line 32
def copy(revision)
  new_path = new_env_path(revision)
  command("cp -r #{@env_path} #{new_path}")
  new_env = Environment.new(new_path)
  new_env.update(revision)
  new_env
end
delete() click to toggle source
# File lib/environmate/environment.rb, line 62
def delete
  FileUtils.remove_entry_secure(@env_path)
end
update(revision) click to toggle source

This will update the current repository and reset it to the specified revision.

  • revision - The revision to update the repository to

# File lib/environmate/environment.rb, line 21
def update(revision)
  update_repo(revision)
  update_submodules if has_submodules?
  update_modules if has_puppetfile?
end
valid?() click to toggle source
# File lib/environmate/environment.rb, line 66
def valid?
  @git.valid?
end

Private Instance Methods

has_puppetfile?() click to toggle source
# File lib/environmate/environment.rb, line 94
def has_puppetfile?
  puppetfile = File.join(@env_path, 'Puppetfile')
  File.exist?(puppetfile)
end
has_submodules?() click to toggle source
# File lib/environmate/environment.rb, line 89
def has_submodules?
  gitmodules = File.join(@env_path, '.gitmodules')
  File.exist?(gitmodules)
end
new_env_path(revision) click to toggle source
# File lib/environmate/environment.rb, line 99
def new_env_path(revision)
  base_dir = Environmate.configuration['environment_path']
  File.join(base_dir, revision)
end
update_modules() click to toggle source
# File lib/environmate/environment.rb, line 83
def update_modules
  Dir.chdir(@env_path) do
    command(@install_modules_command)
  end
end
update_repo(revision) click to toggle source
# File lib/environmate/environment.rb, line 72
def update_repo(revision)
  @git.fetch
  @git.reset_hard
  @git.clean
  @git.checkout(revision)
end
update_submodules() click to toggle source
# File lib/environmate/environment.rb, line 79
def update_submodules
  @git.submodule_update
end