Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logic to properly set arguments value #11

Merged
merged 2 commits into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-10-04 14:22:21 -0400 using RuboCop version 0.47.1.
# on 2017-10-04 21:00:57 -0400 using RuboCop version 0.47.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
# Offense count: 4
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 38

# Offense count: 5
# Offense count: 7
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 135
Max: 143

# Offense count: 6
Style/Documentation:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gemfile.lock should be deleted and added to .gitignore.

remote: .
specs:
graphlient (0.0.4)
graphlient (0.0.5)

GEM
remote: http://rubygems.org/
Expand Down
17 changes: 16 additions & 1 deletion lib/graphlient/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,22 @@ def indent
end

def get_args_str(args)
args.detect { |arg| arg.is_a? Hash }.map { |k, v| "#{k}: #{v}" }.join(',')
args.detect { |arg| arg.is_a? Hash }.map do |k, v|
"#{k}: #{get_arg_value_str(v)}"
end.join(', ')
end

def get_arg_value_str(value)
case value
when String
"\"#{value}\""
when Numeric
value.to_s
when Array
"[#{value.map { |v| get_arg_value_str(v) }.join(', ')}]"
else
value
end
end
end
end
15 changes: 14 additions & 1 deletion spec/graphlient/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@
line_items(name: 'test')
end
end
expect(query.to_s).to eq "{ \ninvoice(id: 10){\n line_items(name: test)\n }\n }"
expect(query.to_s).to eq "{ \ninvoice(id: 10){\n line_items(name: \"test\")\n }\n }"
end

it 'returns expected query with block and local variables with proper type' do
int_arg = 10
float_arg = 10.3
str_arg = 'new name'
array_arg = ['str_item', 2]
query = Graphlient::Query.new do
invoice(id: int_arg, threshold: float_arg, item_list: array_arg) do
line_items(name: str_arg)
end
end
expect(query.to_s).to eq "{ \ninvoice(id: 10, threshold: 10.3, item_list: [\"str_item\", 2]){\n line_items(name: \"new name\")\n }\n }"
end
end
end