Sha256: 45aee7d419fa5e01a7fb97f541fdbebea05943120462ecedb01df0e9c25a5838

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Pcli
  class Step
    class << self
      def ensured
        @ensured = true
      end

      def ensured?
        @ensured.nil? ? @ensured = false : @ensured
      end

      def ensured
        @ensured = true
      end

      def spaced?
        @spaced.nil? ? @spaced = false : @spaced
      end

      def spaced
        @spaced = true
      end
    end

    class Result
      def initialize(success, halt, code)
        @success = success
        @halt = halt
        @code = code
      end

      def success?
        @success
      end

      def halt?
        @halt
      end

      def code(value = nil)
        if value
          @code = value
          self
        else
          @code
        end
      end

      def halt(value = true)
        @halt = value
        self
      end
    end

    delegate :ensured?, :spaced?, to: :class

    protected

    def success
      Result.new(true, false, 0)
    end

    def failure(code = 1)
      Result.new(false, true, code)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pcli-0.1.1 lib/pcli/step.rb
pcli-0.1.0 lib/pcli/step.rb