Module: CodeBrkrGameTraining::Validator
- Included in:
- Code, DifficultyController, Game, User
- Defined in:
- lib/code_brkr_game_training/modules/validator.rb
Overview
Data validation module
Constant Summary collapse
- DataValidError =
Class.new(StandardError)
Instance Method Summary collapse
- #check_contain_hash_key(val, hash) ⇒ Object
- #check_length(data, check) ⇒ Object
- #check_type(data, check_type) ⇒ Object
Instance Method Details
#check_contain_hash_key(val, hash) ⇒ Object
17 18 19 |
# File 'lib/code_brkr_game_training/modules/validator.rb', line 17 def check_contain_hash_key(val, hash) raise DataValidError, 'hash_key_not_found' unless hash.key? val.to_sym end |
#check_length(data, check) ⇒ Object
13 14 15 |
# File 'lib/code_brkr_game_training/modules/validator.rb', line 13 def check_length(data, check) raise DataValidError, 'unexpected_length' unless (check[:min]..check[:max]).cover? data.length end |
#check_type(data, check_type) ⇒ Object
9 10 11 |
# File 'lib/code_brkr_game_training/modules/validator.rb', line 9 def check_type(data, check_type) raise DataValidError, 'unexpected_type' unless data.instance_of? check_type end |