Class: Vocab::Validator::Base
- Inherits:
-
Object
- Object
- Vocab::Validator::Base
- Defined in:
- lib/vocab/validator/base.rb
Instance Method Summary collapse
-
#pre_validate(path) ⇒ Object
Override in subclass.
- #print(path, validation) ⇒ Object
-
#validate ⇒ Object
Returns false if validation fails.
- #validate_file(path) ⇒ Object
Instance Method Details
#pre_validate(path) ⇒ Object
Override in subclass
46 47 48 |
# File 'lib/vocab/validator/base.rb', line 46 def pre_validate( path ) return true end |
#print(path, validation) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vocab/validator/base.rb', line 21 def print( path, validation ) Vocab.ui.say( "Validating: #{path}" ) unless validation[ :missing ].empty? Vocab.ui.say( " Missing keys:" ) validation[ :missing ].each { |missing| Vocab.ui.say( " - #{missing}" ) } end unless validation[ :extra ].empty? Vocab.ui.say( " Extra keys:" ) validation[ :extra ].each { |extra| Vocab.ui.say( " + #{extra}" ) } end end |
#validate ⇒ Object
Returns false if validation fails
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/vocab/validator/base.rb', line 6 def validate ok = true files = files_to_validate Vocab.ui.say( "#{files.size} file(s) to validate in #{@locales_dir}" ) files.each do |path| ok &&= pre_validate( path ) validation = validate_file( path ) print( path, validation ) ok &&= validation[ :missing ] && validation[ :missing ].empty? end return ok end |
#validate_file(path) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/vocab/validator/base.rb', line 35 def validate_file( path ) other = other_keys( path ) english = string_keys( path ) result = {} result[ :missing ] = ( english - other ).sort result[ :extra ] = ( other - english ).sort return result end |