Sha256: 6bb4197ec30d8fe943a790ce536e6b934a15d96a4a3fd4b9dbe160c111379e1a

Contents?: true

Size: 732 Bytes

Versions: 2

Compression:

Stored size: 732 Bytes

Contents

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
          once_helper.state = new_state
          @path = :once
        else
          @path = :otherwise
        end
      end

      def once(&block)
        if @path == :then
          yield
        end
        self
      end

      def otherwise(&block)
        if @path == :otherwise
          yield
        end
        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

2 entries across 2 versions & 1 rubygems

Version Path
mux_tf-0.8.4 lib/mux_tf/once_helper.rb
mux_tf-0.8.3 lib/mux_tf/once_helper.rb