Sha256: 6ee957ba793c673b004bde954cdc5f2279550b741fb79d761b5806bdc3800a88

Contents?: true

Size: 1.49 KB

Versions: 33

Compression:

Stored size: 1.49 KB

Contents

class Card
  class ActManager
    module Stage
      STAGES = [:initialize, :prepare_to_validate, :validate, :prepare_to_store,
                :store, :finalize, :integrate, :after_integrate, :integrate_with_delay].freeze
      stage_index = {}
      STAGES.each_with_index do |stage, i|
        stage_index[stage] = i
      end
      STAGE_INDEX = stage_index.freeze

      def stage_symbol index
        case index
        when Symbol
          return index if STAGE_INDEX[index]
        when Integer
          return STAGES[index] if index < STAGES.size
        end
        raise Card::Error, "not a valid stage index: #{index}"
      end

      def stage_index stage
        case stage
        when Symbol then
          return STAGE_INDEX[stage]
        when Integer then
          return stage
        else
          raise Card::Error, "not a valid stage: #{stage}"
        end
      end

      def stage_ok? opts
        stage && (
        (opts[:during] && in?(opts[:during])) ||
          (opts[:before] && before?(opts[:before])) ||
          (opts[:after] && after?(opts[:after])) ||
          true # no phase restriction in opts
        )
      end

      def before? allowed_phase
        STAGE_INDEX[allowed_phase] > STAGE_INDEX[stage]
      end

      def after? allowed_phase
        STAGE_INDEX[allowed_phase] < STAGE_INDEX[stage]
      end

      def in? allowed_phase
        (allowed_phase.is_a?(Array) && allowed_phase.include?(stage)) ||
          allowed_phase == stage
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
card-1.96.8 lib/card/act_manager/stage.rb
card-1.96.7 lib/card/act_manager/stage.rb
card-1.96.6 lib/card/act_manager/stage.rb
card-1.96.5 lib/card/act_manager/stage.rb
card-1.96.4 lib/card/act_manager/stage.rb
card-1.96.3 lib/card/act_manager/stage.rb
card-1.96.2 lib/card/act_manager/stage.rb
card-1.96.1 lib/card/act_manager/stage.rb
card-1.96.0 lib/card/act_manager/stage.rb
card-1.95.3 lib/card/act_manager/stage.rb
card-1.95.2 lib/card/act_manager/stage.rb
card-1.95.1 lib/card/act_manager/stage.rb
card-1.95.0 lib/card/act_manager/stage.rb
card-1.94.1 lib/card/act_manager/stage.rb
card-1.94.0 lib/card/act_manager/stage.rb
card-1.93.13 lib/card/act_manager/stage.rb
card-1.93.12 lib/card/act_manager/stage.rb
card-1.93.11 lib/card/act_manager/stage.rb
card-1.93.10 lib/card/act_manager/stage.rb
card-1.93.9 lib/card/act_manager/stage.rb