Sha256: e8a2d18354fc33fff85f00cf37fbc634156acc5bf1872afc4b37914342805465

Contents?: true

Size: 820 Bytes

Versions: 5

Compression:

Stored size: 820 Bytes

Contents

require 'easy_command/chainable'

module EasyCommand
  class Result
    include Chainable

    def initialize(content)
      @content = content
    end

    def result
      @content
    end

    def errors
      EasyCommand::Errors.new
    end

    def failure?; false; end
    def success?; true; end

    def on_success
      yield(result) if success?
      self
    end

    def on_failure
      yield(errors) if failure?
      self
    end
  end

  class Success < Result; end

  class Params < Result; end

  class Failure < Result
    def success?; false; end
    def failure?; true; end

    def with_errors(errors)
      @_errors = errors
      self
    end

    def errors
      @_errors ||=
        EasyCommand::Errors.new.tap do |errors|
          errors.add(:result, :failure)
        end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
easy_command-1.0.1 lib/easy_command/result.rb
easy_command-1.0.0 lib/easy_command/result.rb
easy_command-1.0.0.pre.rc3 lib/easy_command/result.rb
easy_command-1.0.0.pre.rc2 lib/easy_command/result.rb
easy_command-1.0.0.pre.rc1 lib/easy_command/result.rb