Module: MalawiHivProgramReports::Utils::ParameterUtils
- Defined in:
- app/services/malawi_hiv_program_reports/utils/parameter_utils.rb
Constant Summary collapse
- LOGGER =
Logger.new($stdout)
Instance Method Summary collapse
-
#fetch_parameter(parameters, field) ⇒ Object
Fetches field from ActiveSupport::Parameters.
- #fetch_parameter_as_date(parameters, field, default = nil) ⇒ Object
Instance Method Details
#fetch_parameter(parameters, field) ⇒ Object
Fetches field from ActiveSupport::Parameters.
This method is just a wrapper around the fetch or raise bad request routine for retrieving parameter values.
17 18 19 20 21 22 |
# File 'app/services/malawi_hiv_program_reports/utils/parameter_utils.rb', line 17 def fetch_parameter(parameters, field) parameters.fetch(field) rescue KeyError => e LOGGER.error("Failed to fetch parameter `#{field}` due to #{e}") raise ::InvalidParameterError, "`#{field}` not found in parameters: #{parameters.to_json}" end |
#fetch_parameter_as_date(parameters, field, default = nil) ⇒ Object
24 25 26 27 28 29 |
# File 'app/services/malawi_hiv_program_reports/utils/parameter_utils.rb', line 24 def fetch_parameter_as_date(parameters, field, default = nil) parameters.fetch(field, default)&.to_date rescue ArgumentError => e LOGGER.error("Failed to fetch parameter `#{field}` due to #{e}") raise ::InvalidParameterError, "Could not parse #{field} as date from: #{parameters.to_json}" end |