Sha256: c040449009fc26037cb5102ebc667de369dfdfaa1e5f94e930655005f74d5d7f

Contents?: true

Size: 829 Bytes

Versions: 6

Compression:

Stored size: 829 Bytes

Contents

module BloodContracts
  module Core
    class Contract
      class << self
        def new(*args)
          input, output =
            if (opts = args.last).is_a?(Hash)
              accumulate_contract = opts.reduce({}) do |acc, (input, output)|
                prev_input, prev_output = acc.first
                { (input | prev_input) => (output | prev_output) }
              end
              accumulate_contract.first
            else
              _validate_args!(args)
              args
            end
          BC::Pipe.new(input, output, names: %i(input output))
        end

        def _validate_args!(args)
          return if args.size == 2
          raise ArgumentError, <<~MESSAGE
            wrong number of arguments (given #{args.size}, expected 2)
          MESSAGE
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
blood_contracts-core-0.3.5 lib/blood_contracts/core/contract.rb
blood_contracts-core-0.3.4 lib/blood_contracts/core/contract.rb
blood_contracts-core-0.3.3 lib/blood_contracts/core/contract.rb
blood_contracts-core-0.3.2 lib/blood_contracts/core/contract.rb
blood_contracts-core-0.3.1 lib/blood_contracts/core/contract.rb
blood_contracts-core-0.3.0 lib/blood_contracts/core/contract.rb