Sha256: 62f173165c3a586160190a104642e2f38b83668c79d7a782f800cd94c8efe780
Contents?: true
Size: 1001 Bytes
Versions: 5
Compression:
Stored size: 1001 Bytes
Contents
# coding: utf-8 module Abak::Flow class Visitor def initialize(*args) options = args.pop if args.last.is_a?(Hash) @objects = args @call = options.fetch(:call) @inspect = options.fetch(:inspect) @asked = false end def ready? @asked = true ready = @objects.map { |o| o.send(@call) }.uniq ready.size == 1 && ready.first end 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 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 private def asked? @asked end end end
Version data entries
5 entries across 5 versions & 1 rubygems