Class: Rvm2::Ui::Multi
- Inherits:
-
Object
- Object
- Rvm2::Ui::Multi
- Defined in:
- lib/rvm2/ui/multi.rb,
lib/rvm2/ui/multi/io_write_router.rb
Defined Under Namespace
Classes: IoWriteRouter
Instance Attribute Summary collapse
-
#handlers ⇒ Object
readonly
Returns the value of attribute handlers.
Instance Method Summary collapse
- #add(handler, *args) ⇒ Object
-
#command(name, &block) ⇒ Object
ui.command “message” { do_something; }.
-
#initialize(rvm2_plugins = nil) ⇒ Multi
constructor
A new instance of Multi.
-
#log(message, type = :log) ⇒ Object
ui.log ‘message’ ui.log ‘message’, :important standard types => :log, :warn, :important, :error in case unsupported type is used :log will be used.
- #remove ⇒ Object
- #stderr ⇒ Object
- #stdout ⇒ Object
- #with(handler, *args, &block) ⇒ Object
Constructor Details
#initialize(rvm2_plugins = nil) ⇒ Multi
Returns a new instance of Multi.
7 8 9 10 |
# File 'lib/rvm2/ui/multi.rb', line 7 def initialize(rvm2_plugins = nil) @rvm2_plugins = rvm2_plugins || Pluginator.find("rvm2", extends: [:first_class]) @handlers = [] end |
Instance Attribute Details
#handlers ⇒ Object (readonly)
Returns the value of attribute handlers.
5 6 7 |
# File 'lib/rvm2/ui/multi.rb', line 5 def handlers @handlers end |
Instance Method Details
#add(handler, *args) ⇒ Object
12 13 14 |
# File 'lib/rvm2/ui/multi.rb', line 12 def add(handler, *args) @handlers << @rvm2_plugins.first_class!('ui/output', handler).new(@rvm2_plugins, *args) end |
#command(name, &block) ⇒ Object
ui.command “message” { do_something; }
27 28 29 30 31 32 33 |
# File 'lib/rvm2/ui/multi.rb', line 27 def command(name, &block) raise "No block given" unless block_given? @handlers.each {|h| h.start(name) } status = block.call @handlers.each {|h| h.finish(status) } status end |
#log(message, type = :log) ⇒ Object
ui.log ‘message’ ui.log ‘message’, :important standard types => :log, :warn, :important, :error in case unsupported type is used :log will be used
39 40 41 |
# File 'lib/rvm2/ui/multi.rb', line 39 def log(, type = :log) @handlers.each {|h| h.log(, type) } end |
#remove ⇒ Object
16 17 18 |
# File 'lib/rvm2/ui/multi.rb', line 16 def remove @handlers.pop end |
#stderr ⇒ Object
47 48 49 |
# File 'lib/rvm2/ui/multi.rb', line 47 def stderr @stderr ||= IoWriteRouter.new(self, :stderr) end |
#stdout ⇒ Object
43 44 45 |
# File 'lib/rvm2/ui/multi.rb', line 43 def stdout @stdout ||= IoWriteRouter.new(self, :stdout) end |
#with(handler, *args, &block) ⇒ Object
20 21 22 23 24 |
# File 'lib/rvm2/ui/multi.rb', line 20 def with(handler, *args, &block) add(handler, *args) block.call remove end |