Class: Vocab::Validator::Rails

Inherits:
Base
  • Object
show all
Defined in:
lib/vocab/validator/rails.rb

Instance Method Summary collapse

Methods inherited from Base

#print, #validate, #validate_file

Constructor Details

#initialize(locales_dir = nil) ⇒ Rails

Returns a new instance of Rails.



5
6
7
# File 'lib/vocab/validator/rails.rb', line 5

def initialize( locales_dir = nil )
  @locales_dir = locales_dir || 'config/locales'
end

Instance Method Details

#files_to_validateObject



17
18
19
# File 'lib/vocab/validator/rails.rb', line 17

def files_to_validate
  return Dir.glob( "#{@locales_dir}/**/*.yml" ).reject { |path| File.basename( path ) == 'en.yml' }
end

#other_keys(path) ⇒ Object



9
10
11
# File 'lib/vocab/validator/rails.rb', line 9

def other_keys( path )
  return flattened_keys( path )
end

#pre_validate(path) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vocab/validator/rails.rb', line 21

def pre_validate( path )
  bom_regex = "\xEF\xBB\xBF".force_encoding("UTF-8")
  File.open( path ) do |file|
    content = file.read.force_encoding( "UTF-8" )
    if content.match( bom_regex )
      Vocab.ui.warn( "Found a leading BOM character in #{path}" )
      return false
    end
    return true
  end
end

#string_keys(path) ⇒ Object



13
14
15
# File 'lib/vocab/validator/rails.rb', line 13

def string_keys( path )
  return flattened_keys( Vocab::Translator::Rails.en_equivalent_path( path ) )
end