module Card::Director::Run

methods for running stages

Public Instance Methods

catch_up_to_stage(next_stage) click to toggle source
# File lib/card/director/run.rb, line 5
def catch_up_to_stage next_stage
  return if @delay && before?(:integrate_with_delay, next_stage)

  upto_stage(next_stage) do |stage|
    run_stage stage
  end
end
delay!() click to toggle source
# File lib/card/director/run.rb, line 21
def delay!
  @delay = true
end
restart() click to toggle source
# File lib/card/director/run.rb, line 25
def restart
  @running = false
  @current_stage_index = nil
end
run_delayed_event(act) { || ... } click to toggle source
# File lib/card/director/run.rb, line 13
def run_delayed_event act
  @running = true
  @act = act
  @current_stage_index = stage_index :integrate_with_delay
  yield
  run_subcard_stages :integrate_with_delay
end

Private Instance Methods

ahead_of_parent?(next_stage) click to toggle source
# File lib/card/director/run.rb, line 116
def ahead_of_parent? next_stage
  head? ? false : after?(parent.current_stage_index, next_stage)
end
check_skipped_stage(stage) click to toggle source
# File lib/card/director/run.rb, line 109
def check_skipped_stage stage
  return unless before? previous_stage_index(stage)

  raise Card::Error, "stage #{previous_stage_symbol stage} was " \
                     "skipped for card #{@card}"
end
each_subcard_director(stage) { |subdir| ... } click to toggle source
# File lib/card/director/run.rb, line 75
def each_subcard_director stage
  subdirectors.each do |subdir|
    yield subdir unless subdir.head? && before?(:integrate, stage)
  end
ensure
  @card.handle_subcard_errors
end
handle_stage(stage, block) { || ... } click to toggle source
# File lib/card/director/run.rb, line 44
def handle_stage stage, block
  case stage
  when :initialize
    prepare_for_phases
  when :store
    # in the store stage it can be necessary that
    # other subcards must be saved before we save this card
    return store(&block)
  end
  yield
end
run_final_stage_callbacks(stage) click to toggle source
# File lib/card/director/run.rb, line 83
def run_final_stage_callbacks stage
  run_stage_callbacks stage, "_final"
end
run_stage(stage, &block) click to toggle source
# File lib/card/director/run.rb, line 32
def run_stage stage, &block
  return true unless valid_next_stage? stage

  # puts "#{@card.name}: #{stage} stage".yellow
  @current_stage_index = stage_index stage
  handle_stage stage, block do
    run_stage_callbacks stage
    run_subcard_stages stage
    run_final_stage_callbacks stage
  end
end
run_stage_callbacks(stage, callback_postfix="") click to toggle source
# File lib/card/director/run.rb, line 56
def run_stage_callbacks stage, callback_postfix=""
  Rails.logger.debug "#{stage}: #{@card.name}"
  # we use abort :success in the :store stage for :save_draft

  callbacks = :"#{stage}#{callback_postfix}_stage"
  if in_or_before?(:store, stage) && !main?
    @card.abortable { @card.run_callbacks callbacks }
  else
    @card.run_callbacks callbacks
  end
end
run_subcard_stages(stage) { |subdir| ... } click to toggle source
# File lib/card/director/run.rb, line 68
def run_subcard_stages stage
  each_subcard_director stage do |subdir|
    condition = block_given? ? yield(subdir) : true
    subdir.catch_up_to_stage stage if condition
  end
end
upto_stage(stage) { |stage_symbol(i)| ... } click to toggle source
# File lib/card/director/run.rb, line 87
def upto_stage stage
  @current_stage_index ||= -1
  (@current_stage_index + 1).upto(stage_index(stage)) do |i|
    yield stage_symbol(i)
  end
end
valid_card?(next_stage) click to toggle source
# File lib/card/director/run.rb, line 105
def valid_card? next_stage
  @card.errors.empty? || in_or_before?(:validate, next_stage)
end
valid_next_stage?(next_stage) click to toggle source
# File lib/card/director/run.rb, line 94
def valid_next_stage? next_stage
  @current_stage_index ||= -1
  return false if @abort ||
                  in_or_after?(next_stage) ||
                  ahead_of_parent?(next_stage) ||
                  !valid_card?(next_stage)

  check_skipped_stage next_stage
  true
end