module Cucumber::Chef::Utility
Public Instance Methods
boot(name=nil)
click to toggle source
# File lib/cucumber/chef/utility.rb, line 129 def boot(name=nil) if !in_chef_repo? message = "It does not look like you are inside a chef-repo! Please relocate to one and execute your command again!" logger.fatal { message } raise message end name and logger.info { "loading #{name}" } logger.info { "boot(#{Cucumber::Chef.config_rb})" } Cucumber::Chef::Config.load Cucumber::Chef::Labfile.load(Cucumber::Chef.labfile) end
build_command(name, *args)
click to toggle source
# File lib/cucumber/chef/utility.rb, line 124 def build_command(name, *args) executable = (Cucumber::Chef.locate(:file, "bin", name) rescue "/usr/bin/env #{name}") [executable, args].flatten.compact.join(" ") end
build_home_dir(user)
click to toggle source
# File lib/cucumber/chef/utility.rb, line 112 def build_home_dir(user) ((user == "root") ? "/root" : "/home/#{user}") end
ensure_directory(dir)
click to toggle source
# File lib/cucumber/chef/utility.rb, line 108 def ensure_directory(dir) FileUtils.mkdir_p(File.dirname(dir)) end
ensure_identity_permissions(identity)
click to toggle source
# File lib/cucumber/chef/utility.rb, line 116 def ensure_identity_permissions(identity) (File.exists?(identity) && File.chmod(0400, identity)) end
external_ip()
click to toggle source
# File lib/cucumber/chef/utility.rb, line 98 def external_ip %x(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//').chomp.strip end
generate_do_not_edit_warning(message=nil)
click to toggle source
# File lib/cucumber/chef/utility.rb, line 86 def generate_do_not_edit_warning(message=nil) warning = Array.new warning << "#" warning << "# WARNING: Automatically generated file; DO NOT EDIT!" warning << [ "# Cucumber-Chef v#{Cucumber::Chef::VERSION}", message ].compact.join(" ") warning << "# Generated on #{Time.now.utc.to_s}" warning << "#" warning.join("\n") end
is_rc?()
click to toggle source
# File lib/cucumber/chef/utility.rb, line 46 def is_rc? ((Cucumber::Chef::VERSION =~ /rc/) || (Cucumber::Chef::VERSION =~ /pre/)) end
locate(type, *args)
click to toggle source
# File lib/cucumber/chef/utility.rb, line 52 def locate(type, *args) pwd = Dir.pwd.split(File::SEPARATOR) (pwd.length - 1).downto(0) do |i| candidate = File.join(pwd[0..i], args) case type when :file if (File.exists?(candidate) && !File.directory?(candidate)) return File.expand_path(candidate) end when :directory if (File.exists?(candidate) && File.directory?(candidate)) return File.expand_path(candidate) end when :any if File.exists?(candidate) return File.expand_path(candidate) end end end message = "Could not locate #{type} '#{File.join(args)}'." raise UtilityError, message end
locate_parent(child)
click to toggle source
# File lib/cucumber/chef/utility.rb, line 78 def locate_parent(child) parent = (locate(:any, child).split(File::SEPARATOR) rescue nil) raise UtilityError, "Could not locate parent of '#{child}'." unless parent File.expand_path(File.join(parent[0..(parent.length - 2)])) end
provider_config()
click to toggle source
# File lib/cucumber/chef/utility.rb, line 104 def provider_config Cucumber::Chef::Config[Cucumber::Chef::Config.provider] end
tag(name=nil)
click to toggle source
# File lib/cucumber/chef/utility.rb, line 120 def tag(name=nil) [ name, "v#{Cucumber::Chef::VERSION}" ].compact.join(" ") end