class Abak::Flow::Inspector

Public Class Methods

new(options = Hash.new) click to toggle source
# File lib/abak-flow/inspector.rb, line 6
def initialize(options = Hash.new)
  @objects = Array.new
  @call_method = options.fetch(:call_method)
  @collect_attribute = options.fetch(:collect_attribute)
end

Public Instance Methods

examine(*args) click to toggle source
# File lib/abak-flow/inspector.rb, line 12
def examine(*args)
  @objects = args
  @fail = @objects.map { |x| x.send(@call_method) }.any? { |x| not !!x }

  self
end
on_fail(&block) click to toggle source
# File lib/abak-flow/inspector.rb, line 32
def on_fail(&block)
  block.call(self) if @fail
end
output() click to toggle source
# File lib/abak-flow/inspector.rb, line 19
def output
  @objects.map do |object|
    next if object.send(@collect_attribute).empty?

    info = ""
    object.send(@collect_attribute).each_with_index do |inf, idx|
      info << "\n  #{idx + 1}. #{inf}"
    end

    "#{Manager.locale.name(object)}#{info}"
  end * "\n"
end