Class: Abak::Flow::Visitor
- Inherits:
-
Object
- Object
- Abak::Flow::Visitor
- Defined in:
- lib/abak-flow/visitor.rb
Instance Method Summary collapse
- #exit_on_fail(command, code = 1) ⇒ Object
-
#initialize(*args) ⇒ Visitor
constructor
A new instance of Visitor.
- #output ⇒ Object
- #ready? ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Visitor
Returns a new instance of Visitor.
5 6 7 8 9 10 11 12 13 |
# File 'lib/abak-flow/visitor.rb', line 5 def initialize(*args) = args.pop if args.last.is_a?(Hash) @objects = args @call = .fetch(:call) @inspect = .fetch(:inspect) @asked = false end |
Instance Method Details
#exit_on_fail(command, code = 1) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/abak-flow/visitor.rb', line 38 def exit_on_fail(command, code = 1) return if ready? say ANSI.red { I18n.t("commands.#{command}.fail") } say ANSI.yellow { output } exit(code) end |
#output ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/abak-flow/visitor.rb', line 22 def output ready? unless asked? @objects.map do |o| next if o.send(@inspect).empty? info = "" name = o.respond_to?(:display_name) ? o.display_name : o.class.name o.send(@inspect).each_with_index do |inf, idx| info << "\n #{idx + 1}. #{inf}" end "\n#{name}#{info}" end * "\n" end |
#ready? ⇒ Boolean
15 16 17 18 19 20 |
# File 'lib/abak-flow/visitor.rb', line 15 def ready? @asked = true ready = @objects.map { |o| o.send(@call) }.uniq ready.size == 1 && ready.first end |