Class: GameValidator::Validator

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Defined in:
lib/game_validator/validator.rb,
lib/game_validator/validator/base.rb,
lib/game_validator/validator/result.rb,
lib/game_validator/validator/result/failure.rb,
lib/game_validator/validator/validate_to_action.rb,
lib/game_validator/validator/result/failure/node.rb,
lib/game_validator/validator/full_validator_coercer.rb,
lib/game_validator/validator/result/failure/builder.rb

Defined Under Namespace

Classes: Base, FullValidatorCoercer, Result, ValidateToAction

Instance Method Summary collapse

Instance Method Details

#call(action_hash:, user:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/game_validator/validator.rb', line 14

def call(action_hash:, user:)
  a = action_hash.dup
  a[:user] = user
  result = validate_player_action_and_user.(a)
  return build_failure.(errors: result.errors) if result.failure?
  validate = full_validator_for[[a[:player_action], a[:user].admin?]]
  result = validate.(action_hash)
  return build_failure.(errors: result.errors) if result.failure?
  result
end