Sha256: 507dfdd353349fb800a0568005e1f460fa23643afbdbf0f33a6eccc53fb3bf82

Contents?: true

Size: 1.7 KB

Versions: 12

Compression:

Stored size: 1.7 KB

Contents

class Card
  before_validation :validation_phase, if: -> { validation_phase_callback? }
  around_save :storage_phase
  after_commit :integration_phase, if: -> { integration_phase_callback? }

  class Director
    # Validation, Storage, and Integration phase handling
    module Phases
      def validation_phase_callback?
        !@only_storage_phase && head?
      end

      def integration_phase_callback?
        !@abort && !@only_storage_phase && main?
      end

      def prepare_for_phases
        @card.prepare_for_phases unless running?
        @card.identify_action
        @running = true
        @subdirectors.each(&:prepare_for_phases)
      end

      def validation_phase
        run_stage :initialize
        run_stage :prepare_to_validate
        run_stage :validate
      ensure
        @card.errors.empty?
      end

      # Unlike other phases, the storage phase takes a block,
      # because it is called by an "around" callback
      def storage_phase &block
        catch_up_to_stage :prepare_to_store # unless @abort
        # puts "before store #{@card.name}: abort:#{@abort}"
        run_stage :store, &block # unless @abort
        run_stage :finalize # unless @abort
        raise ActiveRecord::RecordInvalid, @card if @card.errors.any?
      ensure
        @from_trash = nil
      end

      def integration_phase
        # puts "integration phase: #{@card.name}"
        return if @abort

        @card.restore_changes_information
        run_stage :integrate
        run_stage :after_integrate
        run_stage :integrate_with_delay
      ensure
        @card.clear_changes_information unless @abort
        @card.expire unless Cardio.delaying? # if delaying, then expired by clear
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
card-1.108.1 lib/card/director/phases.rb
card-1.108.0 lib/card/director/phases.rb
card-1.107.0 lib/card/director/phases.rb
card-1.106.0 lib/card/director/phases.rb
card-1.105.6 lib/card/director/phases.rb
card-1.105.5 lib/card/director/phases.rb
card-1.105.4 lib/card/director/phases.rb
card-1.105.3 lib/card/director/phases.rb
card-1.105.2.pre1 lib/card/director/phases.rb
card-1.105.2 lib/card/director/phases.rb
card-1.105.1 lib/card/director/phases.rb
card-1.105.0 lib/card/director/phases.rb