Class: VagrantPlugins::VagrantBosh::Ui
- Inherits:
-
Object
- Object
- VagrantPlugins::VagrantBosh::Ui
- Defined in:
- lib/vagrant-bosh/ui.rb
Class Method Summary collapse
Instance Method Summary collapse
- #debug_msg(key, hash) ⇒ Object
- #for(*extra_i18n_prefix) ⇒ Object
-
#initialize(machine, opts) ⇒ Ui
constructor
A new instance of Ui.
- #msg(key, hash) ⇒ Object
- #msg_string(key, hash) ⇒ Object
- #section(key, hash = {}) ⇒ Object
- #timed_msg(key, hash, &blk) ⇒ Object
Constructor Details
#initialize(machine, opts) ⇒ Ui
Returns a new instance of Ui.
15 16 17 18 19 20 21 22 23 |
# File 'lib/vagrant-bosh/ui.rb', line 15 def initialize(machine, opts) @machine = machine @show_debug = opts.fetch(:show_debug) @i18n_prefix = opts.fetch(:i18n_prefix) @start_time = opts.fetch(:start_time) @logger = Log4r::Logger.new("vagrant::provisioners::bosh::ui") end |
Class Method Details
.for_machine(machine) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/vagrant-bosh/ui.rb', line 7 def self.for_machine(machine) new(machine, { show_debug: !!ENV["DEBUG"], i18n_prefix: nil, start_time: Time.now, }) end |
Instance Method Details
#debug_msg(key, hash) ⇒ Object
68 69 70 |
# File 'lib/vagrant-bosh/ui.rb', line 68 def debug_msg(key, hash) msg(key, hash) if @show_debug end |
#for(*extra_i18n_prefix) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/vagrant-bosh/ui.rb', line 25 def for(*extra_i18n_prefix) self.class.new(@machine, { show_debug: @show_debug, i18n_prefix: ([@i18n_prefix] + extra_i18n_prefix).compact.join("."), start_time: @start_time, }) end |
#msg(key, hash) ⇒ Object
42 43 44 |
# File 'lib/vagrant-bosh/ui.rb', line 42 def msg(key, hash) @machine.ui.info(time_prefix(msg_string(key, hash))) end |
#msg_string(key, hash) ⇒ Object
37 38 39 40 |
# File 'lib/vagrant-bosh/ui.rb', line 37 def msg_string(key, hash) path = @i18n_prefix ? "#{@i18n_prefix}.#{key}" : key I18n.t("bosh.ui.#{path}", hash) end |
#section(key, hash = {}) ⇒ Object
33 34 35 |
# File 'lib/vagrant-bosh/ui.rb', line 33 def section(key, hash={}) msg(key, hash) end |
#timed_msg(key, hash, &blk) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/vagrant-bosh/ui.rb', line 46 def timed_msg(key, hash, &blk) path = @i18n_prefix ? "#{@i18n_prefix}.#{key}" : key title = I18n.t("bosh.ui.#{path}", hash) # Do not show elapsed time in debug mode if @show_debug @machine.ui.info(time_prefix(title)) blk.call return end # In non-debug mode show e.g. "Uploading /var/vcap/bosh/bin/bosh-agent (sudo)... 1.33s" begin t1 = Time.now @machine.ui.info(time_prefix("#{title}..."), new_line: false) blk.call ensure t2 = Time.now @machine.ui.info(" %.2fs" % (t2 - t1), prefix: false) end end |