class RSpec::GraphqlAssistant::ArgumentBuilder
Attributes
arguments_hash[R]
Public Class Methods
new(arguments_hash)
click to toggle source
# File lib/rspec/graphql_assistant/argument_builder.rb, line 6 def initialize(arguments_hash) @arguments_hash = arguments_hash end
Public Instance Methods
call()
click to toggle source
# File lib/rspec/graphql_assistant/argument_builder.rb, line 10 def call process_hash(arguments_hash) end
Private Instance Methods
is_scalar?(arg)
click to toggle source
# File lib/rspec/graphql_assistant/argument_builder.rb, line 51 def is_scalar?(arg) arg.is_a?(Symbol) || arg.is_a?(String) || arg.is_a?(Numeric) || [true, false].include?(arg) || %w[date time].include?(arg.class.to_s.downcase) end
process_array(arg)
click to toggle source
# File lib/rspec/graphql_assistant/argument_builder.rb, line 27 def process_array(arg) result = [] arg.each do |item| result << process_root(item) end result.map { |item| "{#{item}}"}.join(', ') end
process_hash(arg)
click to toggle source
# File lib/rspec/graphql_assistant/argument_builder.rb, line 35 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) if is_scalar?(v) result << "#{arg_name}: #{process_scalar(v)}" elsif v.is_a?(Array) result << "#{arg_name}: [ #{process_root(v)} ]" else result << "#{arg_name}: { #{process_root(v)} }" end end result.join(', ') end
process_root(arg)
click to toggle source
# File lib/rspec/graphql_assistant/argument_builder.rb, line 16 def process_root(arg) return process_hash(arg) if arg.is_a?(Hash) return process_array(arg) if arg.is_a?(Array) process_scalar(arg) if arg.is_a?(Symbol) || arg.is_a?(String) || arg.is_a?(Numeric) end
process_scalar(arg)
click to toggle source
# File lib/rspec/graphql_assistant/argument_builder.rb, line 22 def process_scalar(arg) arg = "\"#{arg}\"" if arg.is_a?(Symbol) || arg.is_a?(String) arg end