module ValidateMyParams

Constants

VERSION

Attributes

_data[R]

Public Instance Methods

validate(param, type:, required:) click to toggle source
# File lib/validate_my_params.rb, line 12
def validate(param, type:, required:)
        param = param.to_sym

        if required && !_data.include?(param)
                raise MissingParam, "#{param} is required but was not provided"
        end

        if _data.include?(param) && !_data[param].is_a?(type)
          raise InvalidParam, "#{param} is not a #{type} as expected"
        end
end
validate_args(data) { |self| ... } click to toggle source
# File lib/validate_my_params.rb, line 7
def validate_args(data, &block)
        @_data = data
        yield self
end