Sha256: 02abc5ffffcfa770497e96209543e9c53befe72863f69d9cf7494cdb5caa4355
Contents?: true
Size: 1.11 KB
Versions: 44
Compression:
Stored size: 1.11 KB
Contents
# frozen_string_literal: true require 'logger' # Utility methods for dealing with ActiveSupport::Parameters objects. module MalawiHivProgramReports module Utils module ParameterUtils LOGGER = Logger.new($stdout) # Fetches field from ActiveSupport::Parameters. # # This method is just a wrapper around the fetch or raise bad request # routine for retrieving parameter values. # # @throws InvalidParameterError - When field is not found in stock_obs 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 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 end end end
Version data entries
44 entries across 44 versions & 1 rubygems