Class: VAProfile::Exceptions::Parser
- Inherits:
-
Object
- Object
- VAProfile::Exceptions::Parser
- 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
- #exception_keys ⇒ Object private
- #exceptions_file ⇒ Object private
-
#known?(exception_key) ⇒ Boolean
Checks if the passed exception key is present in the exceptions_file.
- #known_exceptions ⇒ Object
-
#known_keys ⇒ Array
Parses our exceptions file and returns all of the VAProfile exception keys.
Instance Method Details
#exception_keys ⇒ Object (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_file ⇒ Object (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
31 32 33 |
# File 'lib/va_profile/exceptions/parser.rb', line 31 def known?(exception_key) known_keys.include? exception_key.downcase end |
#known_exceptions ⇒ Object
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_keys ⇒ Array
Parses our exceptions file and returns all of the VAProfile exception keys. Memoizes this value by setting it equal to the @keys instance variable.
21 22 23 |
# File 'lib/va_profile/exceptions/parser.rb', line 21 def known_keys @keys ||= exception_keys end |