Module: Cucumber::Chef::Utility
- Included in:
- Cucumber::Chef
- Defined in:
- lib/cucumber/chef/utility.rb
Instance Method Summary collapse
- #generate_do_not_edit_warning(message = nil) ⇒ Object
- #is_rc? ⇒ Boolean
- #load_knife_config ⇒ Object
- #locate(type, *args) ⇒ Object
- #locate_parent(child) ⇒ Object
- #root ⇒ Object
- #spinner(stdout = STDOUT, stderr = STDERR, stdin = STDIN) ⇒ Object
Instance Method Details
#generate_do_not_edit_warning(message = nil) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/cucumber/chef/utility.rb', line 117 def generate_do_not_edit_warning(=nil) warning = [] warning << "#" warning << "# WARNING: Automatically generated file; DO NOT EDIT!" warning << [ "# Cucumber-Chef v#{Cucumber::Chef::VERSION}", ].compact.join(" ") warning << "# Generated on #{Time.now.utc.to_s}" warning << "#" warning.join("\n") end |
#is_rc? ⇒ Boolean
31 32 33 |
# File 'lib/cucumber/chef/utility.rb', line 31 def is_rc? ((Cucumber::Chef::VERSION =~ /rc/) || (Cucumber::Chef::VERSION =~ /pre/)) end |
#load_knife_config ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/cucumber/chef/utility.rb', line 43 def load_knife_config $logger.debug { "attempting to load cucumber-chef test lab 'knife.rb'" } knife_rb = Cucumber::Chef.locate(:file, ".cucumber-chef", "knife.rb") ::Chef::Config.from_file(knife_rb) $logger.debug { "load_knife_config(#{knife_rb})" } end |
#locate(type, *args) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/cucumber/chef/utility.rb', line 54 def locate(type, *args) pwd = Dir.pwd.split(File::SEPARATOR) $logger.debug { "pwd='#{Dir.pwd}'" } if $logger (pwd.length - 1).downto(0) do |i| candidate = File.join(pwd[0..i], args) $logger.debug { "candidate='#{candidate}'" } if $logger case type when :file if (File.exists?(candidate) && !File.directory?(candidate)) result = File.(candidate) $logger.debug { "result='#{result}'" } if $logger return result end when :directory if (File.exists?(candidate) && File.directory?(candidate)) result = File.(candidate) $logger.debug { "result='#{result}'" } if $logger return result end when :any if File.exists?(candidate) result = File.(candidate) $logger.debug { "result='#{result}'" } if $logger return result end end end = "Could not locate #{type} '#{File.join(args)}'." $logger.fatal { } if $logger raise UtilityError, end |
#locate_parent(child) ⇒ Object
89 90 91 92 93 |
# File 'lib/cucumber/chef/utility.rb', line 89 def locate_parent(child) parent = (locate(:any, child).split(File::SEPARATOR) rescue nil) raise UtilityError, "Could not locate parent of '#{child}'." unless parent File.(File.join(parent[0..(parent.length - 2)])) end |
#root ⇒ Object
37 38 39 |
# File 'lib/cucumber/chef/utility.rb', line 37 def root File.(File.join(File.dirname(__FILE__), "..", "..", ".."), File.dirname(__FILE__)) end |
#spinner(stdout = STDOUT, stderr = STDERR, stdin = STDIN) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/cucumber/chef/utility.rb', line 97 def spinner(stdout=STDOUT, stderr=STDERR, stdin=STDIN) spinning_chars = %w[| / - \\] count = 0 spinner = Thread.new do while count do stdout.print spinning_chars[(count+=1) % spinning_chars.length] stdout.flush if stdout.respond_to?(:flush) sleep(0.25) stdout.print "\b" stdout.flush if stdout.respond_to?(:flush) end end yield.tap do count = false spinner.join end end |