Module: Awsam::Utils
- Defined in:
- lib/awsam/utils.rb
Class Method Summary collapse
-
.bash_environ(envs) ⇒ Object
Print the appropriate environment variables set commands for bash.
-
.confdir_scan(dir) ⇒ Object
Scan a directory yielding for each file.
-
.get_default(basedir) ⇒ Object
Get the target of the default link.
-
.remove_default(basedir) ⇒ Object
Remove the default link.
-
.set_default(basedir, target) ⇒ Object
Set the default resource with link directory and target.
Class Method Details
.bash_environ(envs) ⇒ Object
Print the appropriate environment variables set commands for bash
13 14 15 16 17 |
# File 'lib/awsam/utils.rb', line 13 def self::bash_environ(envs) envs.each_pair do |k, v| puts "export #{k}=\"#{v}\"" end end |
.confdir_scan(dir) ⇒ Object
Scan a directory yielding for each file
5 6 7 8 9 10 |
# File 'lib/awsam/utils.rb', line 5 def self.confdir_scan(dir) Dir.entries(dir).each do |name| next if name == '.' || name == '..' || name == Awsam::DEFAULT_LINK_NAME yield(name) end end |
.get_default(basedir) ⇒ Object
Get the target of the default link
40 41 42 43 |
# File 'lib/awsam/utils.rb', line 40 def self.get_default(basedir) link = File.join(basedir, Awsam::DEFAULT_LINK_NAME) File.exist?(link) ? File.readlink(link) : nil end |
.remove_default(basedir) ⇒ Object
Remove the default link
46 47 48 |
# File 'lib/awsam/utils.rb', line 46 def self.remove_default(basedir) FileUtils.rm File.join(basedir, Awsam::DEFAULT_LINK_NAME) end |
.set_default(basedir, target) ⇒ Object
Set the default resource with link directory and target
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/awsam/utils.rb', line 20 def self.set_default(basedir, target) link = File.join(basedir, Awsam::DEFAULT_LINK_NAME) if File.exist?(link) begin FileUtils.rm(link) rescue => err $stderr.puts "Failed to remove link #{link}: #{err.}" return false end end begin FileUtils.ln_s(target, link) rescue => err $stderr.puts "Failed to create symlink: #{err.}" return false end true end |