class RSpec::GraphqlAssistant::ArgumentBuilderWithVars

Attributes

arguments_arr[R]

Public Class Methods

new(arguments_arr) click to toggle source
# File lib/rspec/graphql_assistant/argument_builder_with_vars.rb, line 6
def initialize(arguments_arr)
  @arguments_arr = arguments_arr
end

Public Instance Methods

call() click to toggle source
# File lib/rspec/graphql_assistant/argument_builder_with_vars.rb, line 10
def call
  result = []
  arguments_arr.each do |arg|
    result << process_root(arg)
  end
  result.join ', '
end

Private Instance Methods

process_array(arg) click to toggle source
# File lib/rspec/graphql_assistant/argument_builder_with_vars.rb, line 31
def process_array(arg)
  result = []
  arg.each do |item|
    result << process_root(item)
  end
  result.join(', ')
end
process_hash(arg) click to toggle source
# File lib/rspec/graphql_assistant/argument_builder_with_vars.rb, line 39
def process_hash(arg)
  result = ''
  arg.each do |k, v|
    arg_name = k
    arg_name = k.to_s.camelize(:lower) if k.is_a?(Symbol)
    arg_value = process_root(v)
    result << "#{arg_name}: { #{arg_value} }"
  end
  result
end
process_root(arg) click to toggle source
# File lib/rspec/graphql_assistant/argument_builder_with_vars.rb, line 20
def process_root(arg)
  return process_hash(arg) if arg.is_a?(Hash)
  return process_array(arg) if arg.is_a?(Array)
  process_string_or_symbol(arg) if arg.is_a?(Symbol) || arg.is_a?(String)
end
process_string_or_symbol(arg) click to toggle source
# File lib/rspec/graphql_assistant/argument_builder_with_vars.rb, line 26
def process_string_or_symbol(arg)
  arg = arg.to_s.camelize(:lower) if arg.is_a?(Symbol)
  "#{arg}: $#{arg}"
end