module FlowObject::Base::ClassMethods

Public Instance Methods

accept(*values) click to toggle source
# File lib/flow_object/base.rb, line 61
def accept(*values)
  @initial_values = values
  self
end
call(flow: :main) click to toggle source
# File lib/flow_object/base.rb, line 66
def call(flow: :main)
  __fo_resolve__(__fo_process__(flow: flow))
end
callbacks() click to toggle source
# File lib/flow_object/base.rb, line 47
def callbacks
  @callbacks ||= Callbacks.new
end
flow(name = :main, &block) click to toggle source
# File lib/flow_object/base.rb, line 70
def flow(name = :main, &block)
  wrap(name, delegate: true, on_exception: :halt, &block)
end
from(input) click to toggle source
# File lib/flow_object/base.rb, line 51
def from(input)
  @in = input
  self
end
inherited(subclass) click to toggle source
Calls superclass method
# File lib/flow_object/base.rb, line 36
def inherited(subclass)
  super
  subclass.from(self.in)
  subclass.to(self.out)
  subclass.after_input_initialize(&self.after_input_initialize)
  subclass.after_flow_initialize(&self.after_flow_initialize)
  subclass.after_input_check(&self.after_input_check)
  subclass.after_flow_check(&self.after_flow_check)
  subclass.after_output_initialize(&self.after_output_initialize)
end
to(output) click to toggle source
# File lib/flow_object/base.rb, line 56
def to(output)
  @out = output
  self
end

Private Instance Methods

__fo_build_flow__(flow, step_name, group, object) click to toggle source
# File lib/flow_object/base.rb, line 90
def __fo_build_flow__(flow, step_name, group, object)
  public_send(:"build_#{flow}", title: step_name, group: group, object: object)
end
__fo_notify_error__(handler, step) click to toggle source
# File lib/flow_object/base.rb, line 137
def __fo_notify_error__(handler, step)
  if handler.output.respond_to?(:"on_#{step}_failure")
    handler.output.public_send(:"on_#{step}_failure")
  elsif handler.output.respond_to?(:on_failure)
    handler.output.on_failure(step)
  elsif handler.respond_to?(:"on_#{step}_failure")
    handler.public_send(:"on_#{step}_failure")
  else
    handler.on_failure(step)
  end
end
__fo_notify_exception__(handler, exception) click to toggle source
# File lib/flow_object/base.rb, line 123
def __fo_notify_exception__(handler, exception)
  step = exception.step_id.title
  if handler.output.respond_to?(:"on_#{step}_exception")
    handler.output.public_send(:"on_#{step}_exception", exception)
  elsif handler.output.respond_to?(:on_exception)
    handler.output.on_exception(exception)
  elsif handler.respond_to?(:"on_#{step}_exception")
    handler.public_send(:"on_#{step}_exception", exception)
  else
    handler.on_exception(exception)
  end
  __fo_notify_error__(handler, exception.step_id.title)
end
__fo_notify_success__(handler) click to toggle source
# File lib/flow_object/base.rb, line 149
def __fo_notify_success__(handler)
  if handler.output.respond_to?(:on_success)
    handler.output.on_success
  else
    handler.on_success
  end
end
__fo_process__(flow: :main) click to toggle source
# File lib/flow_object/base.rb, line 85
def __fo_process__(flow: :main)
  plan    = __fo_build_flow__(flow, self.in, :input, __fo_wrap_input__)
  Runner.new(plan, callbacks, method(:halt_flow?)).execute_plan
end
__fo_resolve__(runner) click to toggle source
# File lib/flow_object/base.rb, line 111
def __fo_resolve__(runner)
  new(runner.flow.public_send(runner.step_name), runner.step_name).tap do |handler|
    if runner.flow.exceptional?
      __fo_notify_exception__(handler, runner.flow.exception)
    elsif runner.failure
      __fo_notify_error__(handler, runner.step_name)
    else
      __fo_notify_success__(handler)
    end
  end
end
__fo_wrap_input__() click to toggle source
# File lib/flow_object/base.rb, line 94
def __fo_wrap_input__
  return initial_values if self.in.nil?
  input_class = public_send(:"#{self.in}_input_class")
  return initial_values if input_class.nil?
  public_send(:"new_#{self.in}_input_instance", *initial_values)
end
__fo_wrap_output__() click to toggle source
# File lib/flow_object/base.rb, line 101
def __fo_wrap_output__
  # rescue NoMethodError => ex
  # "You have not define output class. Please add `output :#{self.out}`"
  return if self.out.nil?
  return unless self.respond_to?(:"#{self.out}_output_class")
  output_class = public_send(:"#{self.out}_output_class")
  return if output_class.nil?
  public_send(:"new_#{self.out}_output_instance")
end
halt_flow?(object, id) click to toggle source
# File lib/flow_object/base.rb, line 81
def halt_flow?(object, id)
  false
end