Class: Usps::Imis::Config
- Inherits:
-
Object
- Object
- Usps::Imis::Config
- Defined in:
- lib/usps/imis/config.rb
Overview
API Configuration
Constant Summary collapse
- IMIS_ROOT_URL_PROD =
'https://portal.americasboatingclub.org'- IMIS_ROOT_URL_DEV =
'https://abcdev.imiscloud.com'- REQUIRED_CONFIGS =
%w[imis_id_query_name username password].freeze
Instance Attribute Summary collapse
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#imis_id_query_name ⇒ Object
Returns the value of attribute imis_id_query_name.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#logger_file ⇒ Object
Returns the value of attribute logger_file.
-
#logger_level ⇒ Object
readonly
Returns the value of attribute logger_level.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#filtered_parameters ⇒ Object
Parameters to filter out of logging.
- #global_log_path ⇒ Object
- #global_log_path=(path) ⇒ Object
- #global_logger ⇒ Object
-
#hostname ⇒ Object
Environment-specific API endpoint hostname.
-
#initialize {|_self| ... } ⇒ Config
constructor
A new instance of Config.
-
#instance_variables_to_inspect ⇒ Object
Ruby 3.5 instance variable filter.
- #silence! ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Config
Returns a new instance of Config.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/usps/imis/config.rb', line 21 def initialize @environment = default_environment @imis_id_query_name = ENV.fetch('IMIS_ID_QUERY_NAME', nil) @username = ENV.fetch('IMIS_USERNAME', nil) @password = ENV.fetch('IMIS_PASSWORD', nil) @base_logger = Logger.new($stdout, level: :info) @logger = ActiveSupport::TaggedLogging.new(@base_logger) yield self if block_given? @logger_level = logger.class::SEV_LABEL[logger.level].downcase.to_sym end |
Instance Attribute Details
#environment ⇒ Object
Returns the value of attribute environment.
19 20 21 |
# File 'lib/usps/imis/config.rb', line 19 def environment @environment end |
#imis_id_query_name ⇒ Object
Returns the value of attribute imis_id_query_name.
18 19 20 |
# File 'lib/usps/imis/config.rb', line 18 def imis_id_query_name @imis_id_query_name end |
#logger ⇒ Object
Returns the value of attribute logger.
19 20 21 |
# File 'lib/usps/imis/config.rb', line 19 def logger @logger end |
#logger_file ⇒ Object
Returns the value of attribute logger_file.
19 20 21 |
# File 'lib/usps/imis/config.rb', line 19 def logger_file @logger_file end |
#logger_level ⇒ Object (readonly)
Returns the value of attribute logger_level.
19 20 21 |
# File 'lib/usps/imis/config.rb', line 19 def logger_level @logger_level end |
#password ⇒ Object
Returns the value of attribute password.
18 19 20 |
# File 'lib/usps/imis/config.rb', line 18 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
18 19 20 |
# File 'lib/usps/imis/config.rb', line 18 def username @username end |
Instance Method Details
#filtered_parameters ⇒ Object
Parameters to filter out of logging
88 |
# File 'lib/usps/imis/config.rb', line 88 def filtered_parameters = %i[password] |
#global_log_path ⇒ Object
57 58 59 |
# File 'lib/usps/imis/config.rb', line 57 def global_log_path @global_log_path || self.global_log_path = '/var/log/imis/imis.log' end |
#global_log_path=(path) ⇒ Object
61 62 63 64 65 |
# File 'lib/usps/imis/config.rb', line 61 def global_log_path=(path) @global_log_path = path @global_logger = build_global_logger global_log_path end |
#global_logger ⇒ Object
50 51 52 53 54 55 |
# File 'lib/usps/imis/config.rb', line 50 def global_logger return @global_logger if @global_logger global_log_path @global_logger end |
#hostname ⇒ Object
Environment-specific API endpoint hostname
75 76 77 78 79 80 |
# File 'lib/usps/imis/config.rb', line 75 def hostname return IMIS_ROOT_URL_PROD if environment.production? return IMIS_ROOT_URL_DEV if environment.development? raise Errors::ConfigError, "Unexpected API environment: #{environment}" end |
#instance_variables_to_inspect ⇒ Object
Ruby 3.5 instance variable filter
84 |
# File 'lib/usps/imis/config.rb', line 84 def instance_variables_to_inspect = instance_variables - %i[@password @base_logger @logger @global_logger] |
#silence! ⇒ Object
67 68 69 |
# File 'lib/usps/imis/config.rb', line 67 def silence! self.logger = Logger.new(nil) end |
#validate! ⇒ Object
90 91 92 93 94 95 |
# File 'lib/usps/imis/config.rb', line 90 def validate! missing_config = REQUIRED_CONFIGS.filter_map { it if public_send(it).nil? } return if missing_config.empty? raise Errors::ConfigError, "Missing required configuration: #{missing_config.join(', ')}" end |