class AllSystems::Interactor

Public Instance Methods

go!() click to toggle source
# File lib/all_systems/interactor.rb, line 3
def go!
  raise AbstractMethodError, "please define #{__method__} for #{name} interactor"
end
name() click to toggle source
# File lib/all_systems/interactor.rb, line 12
def name
  self.class.name || 'Anonymous'
end
on(conditional_outcome) { |*output| ... } click to toggle source
# File lib/all_systems/interactor.rb, line 29
def on(conditional_outcome)
  yield *output if outcome? conditional_outcome
end
outcome() click to toggle source
# File lib/all_systems/interactor.rb, line 16
def outcome
  result.first
end
outcome?(predicate) click to toggle source
# File lib/all_systems/interactor.rb, line 20
def outcome?(predicate)
  raise UnknownOutcomeError unless outcomes.include? predicate
  predicate == outcome
end
outcomes() click to toggle source
# File lib/all_systems/interactor.rb, line 7
def outcomes
  # TODO throw error on abstract
  []
end
output() click to toggle source
# File lib/all_systems/interactor.rb, line 25
def output
  result.drop 1
end

Private Instance Methods

go() click to toggle source
# File lib/all_systems/interactor.rb, line 35
def go
  catch(:report) do
    go!
    raise NoOutcomeError, "#{name} concluded without reporting an outcome"
  end
end
method_missing(method_symbol, *args, &block) click to toggle source
Calls superclass method
# File lib/all_systems/interactor.rb, line 51
def method_missing(method_symbol, *args, &block)
  case method_symbol
  when *outcomes
    return on method_symbol, &block
  when /report_([^?]+)/
    report $1.to_sym, *args
  when /([^?]+)\?/
    super unless outcomes.include? $1.to_sym
    outcome? $1.to_sym
  else
    super
  end
end
report(*result) click to toggle source
# File lib/all_systems/interactor.rb, line 46
def report(*result)
  raise UnknownOutcomeReportError unless outcomes.include? result.first
  throw :report, result
end
result() click to toggle source
# File lib/all_systems/interactor.rb, line 42
def result
  @result ||= go
end