Module: TestLab::Utility::Misc
- Included in:
- TestLab, Container, Network, Node, Provisioner::HostsFile, Provisioner::NFSMount, Provisioner::Route, TestLab::Utility
- Defined in:
- lib/testlab/utility/misc.rb
Overview
Misc Module
Instance Method Summary collapse
- #do_provisioner_callbacks(object, action, ui) ⇒ Object
- #format_message(message) ⇒ Object
- #format_object_action(object, action, color) ⇒ Object
- #please_wait(options = {}, &block) ⇒ Object
- #sudo ⇒ Object
- #sudo_prompt ⇒ Object
Instance Method Details
#do_provisioner_callbacks(object, action, ui) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/testlab/utility/misc.rb', line 50 def do_provisioner_callbacks(object, action, ui) klass = object.class.to_s.split('::').last method_name = %(on_#{klass.downcase}_#{action.to_s.downcase}).to_sym object.provisioners.each do |provisioner| ui.logger.info { ">>>>> #{object.id.to_s.upcase} #{klass.upcase} #{action.to_s.upcase} [#{method_name}] (#{provisioner}) <<<<<" } p = provisioner.new(object.config, ui) p.respond_to?(method_name) and p.send(method_name, object) end end |
#format_message(message) ⇒ Object
18 19 20 |
# File 'lib/testlab/utility/misc.rb', line 18 def () "[".blue + "TL".blue.bold + "]".blue + " " + end |
#format_object_action(object, action, color) ⇒ Object
12 13 14 15 16 |
# File 'lib/testlab/utility/misc.rb', line 12 def format_object_action(object, action, color) klass = object.class.to_s.split('::').last "#{klass} #{object.id} #{action}".downcase.send(color).bold end |
#please_wait(options = {}, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/testlab/utility/misc.rb', line 22 def please_wait(={}, &block) ui = [:ui] = [:message] mark = ([:mark] || "Completed in %0.4f seconds!") !block_given? and raise MiscError, "You must supply a block!" ui.nil? and raise MiscError, "You must supply a ZTK::UI object!" .nil? and raise MiscError, "You must supply a message!" use_spinner = true msg = ("#{message} ") length = msg.uncolor.length max = (length >= 60 ? (length+1) : (60 - length)) mrk = ((' ' * max) + "# #{mark}\n") if (ui.logger.respond_to?(:loggers) && ui.logger.loggers.is_a?(Array)) if ui.logger.loggers.count > 1 use_spinner = false mrk = ("#{message} - #{mark}\n") msg = ("#{message} - Starting...\n") end end ZTK::Benchmark.bench(:ui => ui, :message => msg, :mark => mrk, :use_spinner => use_spinner) do yield end end |
#sudo ⇒ Object
61 62 63 |
# File 'lib/testlab/utility/misc.rb', line 61 def sudo %(sudo -p '#{sudo_prompt}') end |
#sudo_prompt ⇒ Object
65 66 67 |
# File 'lib/testlab/utility/misc.rb', line 65 def sudo_prompt %(sudo password for %u@%h: ) end |