Sha256: 6118965345647d0023d49cd028c958d33e98c285422cfe37781242d032aadcfb

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

# frozen string literal: true

require 'dry-initializer'
require 'spy_alley_application/types/validation_builder'

module SpyAlleyApplication
  module Validator
    class NewGameBuilder
      include Dry::Initializer.define -> do
        option :assign_seats, type: ::Types::Callable, reader: :private
        option :assign_spy_identities, ::Types::Callable, reader: :private
        option :build_failure, type: ::Types::Callable, 
          default: ->{GameValidator::Validator::Result::Failure::Builder::new}
        option :generate_new_game, type: ::Types::Callable, reader: :private
        option :validate_new_game, type: ::Types::Callable, reader: :private
      end

      def call(action_hash:, user:)
        sa = validate_new_game.(action_hash)
        return ->(**args){build_failure.(errors: sa.errors)} if sa.failure?
        seat_assignments = assign_seats.(sa[:seat_assignments])
        seat_assignments = assign_spy_identities.(seat_assignments)
        ->(change_orders:) do
          generate_new_game.(
            seat_assignments: seat_assignments,
            change_orders: change_orders)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spy_alley_application-0.3.2 lib/spy_alley_application/validator/new_game_builder.rb
spy_alley_application-0.3.1 lib/spy_alley_application/validator/new_game_builder.rb
spy_alley_application-0.3.0 lib/spy_alley_application/validator/new_game_builder.rb