module ActiveGraphql::Client::Actions::VariableDetectable

handles all action details which are specific for query type request

Public Instance Methods

variable_attributes(attributes) click to toggle source
# File lib/active_graphql/client/actions/variable_detectable.rb, line 8
def variable_attributes(attributes)
  variables_or_nil = attributes.transform_values do |value|
    if value.is_a?(Hash)
      variable_attributes(value)
    elsif variable_value?(value)
      value
    elsif value.is_a?(Array)
      variable_attributes(value.map.with_index { |val, i| [i, val] }.to_h)
    end
  end

  flatten_keys(variables_or_nil).select { |_, val| val.present? }
end
variable_value?(value) click to toggle source
# File lib/active_graphql/client/actions/variable_detectable.rb, line 22
def variable_value?(value)
  kind_of_file?(value) || (value.is_a?(Array) && kind_of_file?(value.first))
end

Private Instance Methods

flatten_keys(attributes, parent_key: nil) click to toggle source
# File lib/active_graphql/client/actions/variable_detectable.rb, line 28
def flatten_keys(attributes, parent_key: nil)
  flattened = {}
  attributes.each do |key, value|
    full_key = [parent_key, key].compact.join('_').to_sym
    if value.is_a?(Hash)
      flattened.merge!(flatten_keys(value, parent_key: full_key))
    else
      flattened[full_key] = value
    end
  end
  flattened
end
kind_of_file?(value) click to toggle source
# File lib/active_graphql/client/actions/variable_detectable.rb, line 41
def kind_of_file?(value)
  value.is_a?(File)
end