Class: Abak::Flow::Inspector

Inherits:
Object
  • Object
show all
Defined in:
lib/abak-flow/inspector.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = Hash.new) ⇒ Inspector

Returns a new instance of Inspector.



6
7
8
9
10
# 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

Instance Method Details

#examine(*args) ⇒ Object



12
13
14
15
16
17
# 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) ⇒ Object



32
33
34
# File 'lib/abak-flow/inspector.rb', line 32

def on_fail(&block)
  block.call(self) if @fail
end

#outputObject



19
20
21
22
23
24
25
26
27
28
29
30
# 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