Sha256: 8224fd23d0fc8328599dc20aad0b228b317957a51a365a0362da9b7e14a292a2

Contents?: true

Size: 703 Bytes

Versions: 3

Compression:

Stored size: 703 Bytes

Contents

# frozen_string_literal: true

module MuxTf
  class OnceHelper
    # once = OnceHelper.new
    # once.for(:phase).once { ... }.otherwise { ... }

    class StateEvaluator
      def initialize(once_helper, new_state)
        if once_helper.state == new_state
          @path = :otherwise
        else
          once_helper.state = new_state
          @path = :once
        end
      end

      def once
        yield if @path == :then
        self
      end

      def otherwise
        yield if @path == :otherwise
        self
      end
    end

    def initialize
      @state = nil
    end

    attr_accessor :state

    def for(new_state)
      StateEvaluator.new(self, new_state)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mux_tf-0.11.0 lib/mux_tf/once_helper.rb
mux_tf-0.10.0 lib/mux_tf/once_helper.rb
mux_tf-0.9.0 lib/mux_tf/once_helper.rb