ebf98f27c4
Enables frozen string for the following: * lib/gitlab/fogbugz_import/**/*.rb * lib/gitlab/gfm/**/*.rb * lib/gitlab/git/**/*.rb * lib/gitlab/gitaly_client/**/*.rb * lib/gitlab/gitlab_import/**/*.rb * lib/gitlab/google_code_import/**/*.rb * lib/gitlab/gpg/**/*.rb * lib/gitlab/grape_logging/**/*.rb * lib/gitlab/graphql/**/*.rb * lib/gitlab/graphs/**/*.rb * lib/gitlab/hashed_storage/**/*.rb * lib/gitlab/health_checks/**/*.rb Partially address gitlab-org/gitlab-ce#47424.
39 lines
846 B
Ruby
39 lines
846 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Gitlab
|
|
module Graphql
|
|
class Variables
|
|
Invalid = Class.new(Gitlab::Graphql::StandardGraphqlError)
|
|
|
|
def initialize(param)
|
|
@param = param
|
|
end
|
|
|
|
def to_h
|
|
ensure_hash(@param)
|
|
end
|
|
|
|
private
|
|
|
|
# Handle form data, JSON body, or a blank value
|
|
def ensure_hash(ambiguous_param)
|
|
case ambiguous_param
|
|
when String
|
|
if ambiguous_param.present?
|
|
ensure_hash(JSON.parse(ambiguous_param))
|
|
else
|
|
{}
|
|
end
|
|
when Hash, ActionController::Parameters
|
|
ambiguous_param
|
|
when nil
|
|
{}
|
|
else
|
|
raise Invalid, "Unexpected parameter: #{ambiguous_param}"
|
|
end
|
|
rescue JSON::ParserError => e
|
|
raise Invalid.new(e)
|
|
end
|
|
end
|
|
end
|
|
end
|