Class: VAProfile::Exceptions::Parser

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/va_profile/exceptions/parser.rb

Overview

This class parses all of the VAProfile exception keys from config/locales/exceptions.en.yml and saves them to an instance variable. For performance reasons, the Singleton Pattern is used. This allows the file system to be hit one time, when a server instance is initialized. From that point forward, the exception keys are saved to an instance variable in this class, thereby eliminating the need for the file system to be hit repeatedly.

Instance Method Summary collapse

Instance Method Details

#exception_keysObject (private)



43
44
45
46
47
48
# File 'lib/va_profile/exceptions/parser.rb', line 43

def exception_keys
  known_exceptions
    .keys
    .sort
    .map(&:downcase)
end

#exceptions_fileObject (private)



50
51
52
53
54
# File 'lib/va_profile/exceptions/parser.rb', line 50

def exceptions_file
  config = Rails.root.join('config', 'locales', 'exceptions.en.yml')

  YAML.load_file(config, aliases: true)
end

#known?(exception_key) ⇒ Boolean

Checks if the passed exception key is present in the exceptions_file

Parameters:

  • exception_key (String)

    A VAProfile exception key from config/locales/exceptions.en.yml For example, ‘VET360_ADDR133’

Returns:

  • (Boolean)


31
32
33
# File 'lib/va_profile/exceptions/parser.rb', line 31

def known?(exception_key)
  known_keys.include? exception_key.downcase
end

#known_exceptionsObject



35
36
37
38
39
# File 'lib/va_profile/exceptions/parser.rb', line 35

def known_exceptions
  exceptions_file
    .dig('en', 'common', 'exceptions')
    .select { |key, _| key.include? 'VET360_' }
end

#known_keysArray

Parses our exceptions file and returns all of the VAProfile exception keys. Memoizes this value by setting it equal to the @keys instance variable.

Returns:

  • (Array)

    An array of lowercased, alphabetized, VAProfile exception keys



21
22
23
# File 'lib/va_profile/exceptions/parser.rb', line 21

def known_keys
  @keys ||= exception_keys
end