Sha256: 95be505ce29ed3d97bcc882261d6f07263af313c07d0aab56eded9123abd74d3

Contents?: true

Size: 808 Bytes

Versions: 8

Compression:

Stored size: 808 Bytes

Contents

# typed: true
# frozen_string_literal: true

require 'dry/monads/result'
require 'dry/validation'
require 'dry/matcher/result_matcher'
require 'rider_kick/use_cases/contract'

module RiderKick
  module UseCases
    class AbstractUseCase
      include Dry::Monads[:result]

      def self.contract(base_contract = Contract, &proc)
        @contract ||= Class.new(base_contract, &proc)
      end

      def self.contract!(args)
        context  = args.fetch(:context, {})
        @results = @contract.new(context).call(args)
      end

      def initialize(contract)
        @contract = contract
      end

      def build_parameter!
        if @contract.success?
          Success(Hashie::Mash.new(@contract.to_h))
        else
          Failure(@contract.errors.to_h)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rider-kick-0.0.8 lib/rider_kick/use_cases/abstract_use_case.rb
rider-kick-0.0.7 lib/rider_kick/use_cases/abstract_use_case.rb
rider-kick-0.0.6 lib/rider_kick/use_cases/abstract_use_case.rb
rider-kick-0.0.5 lib/rider_kick/use_cases/abstract_use_case.rb
rider-kick-0.0.4 lib/rider_kick/use_cases/abstract_use_case.rb
rider-kick-0.0.3 lib/rider_kick/use_cases/abstract_use_case.rb
rider-kick-0.0.2 lib/rider_kick/use_cases/abstract_use_case.rb
rider-kick-0.0.1 lib/rider_kick/use_cases/abstract_use_case.rb