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
link(puppet_env)
click to toggle source
This will create a environment link to the repository
-
puppet_env
- The name of the link/environment
# File lib/environmate/environment.rb, line 43 def link(puppet_env) unless links.include?(puppet_env) temp_link_path = new_env_path(SecureRandom.hex) real_link_path = new_env_path(puppet_env) # relinking is not atomic in linux, but mv is # so we create a temporary link and rename it File.symlink(@env_path, temp_link_path) File.rename(temp_link_path, real_link_path) end end
links()
click to toggle source
get a list of all the links to this environment
# File lib/environmate/environment.rb, line 55 def links found_links = EnvironmentManager.links.find_all do |link,target| target == @name end found_links.map{|link, target| link} 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