diff --git a/.gitignore b/.gitignore index 5e1422c..1115c98 100644 --- a/.gitignore +++ b/.gitignore @@ -42,9 +42,9 @@ build-iPhoneSimulator/ # for a library or gem, you might want to ignore these files since the code is # intended to run in multiple environments; otherwise, check them in: -# Gemfile.lock -# .ruby-version -# .ruby-gemset +Gemfile.lock +.ruby-version +.ruby-gemset # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d4e25ec..4dffac9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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: diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a39f20..bd5e736 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ * Your contribution here. +* [#11](https://github.com/ashkan18/graphlient/pull/11): Fix issue with argument types - [@ashkan18](https://github.com/ashkan18). + ### 0.0.4 (10/4/2017) * [#8](https://github.com/ashkan18/graphlient/pull/8): Handle HTTP errors and raise `Graphlient::Errors::HTTP` on failure - [@dblock](https://github.com/dblock). diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 03d7d0d..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,64 +0,0 @@ -PATH - remote: . - specs: - graphlient (0.0.4) - -GEM - remote: http://rubygems.org/ - specs: - addressable (2.5.2) - public_suffix (>= 2.0.2, < 4.0) - ast (2.3.0) - byebug (9.1.0) - crack (0.4.3) - safe_yaml (~> 1.0.0) - diff-lcs (1.3) - hashdiff (0.3.6) - parser (2.4.0.0) - ast (~> 2.2) - powerpack (0.1.1) - public_suffix (3.0.0) - rainbow (2.2.2) - rake - rake (12.1.0) - rspec (3.6.0) - rspec-core (~> 3.6.0) - rspec-expectations (~> 3.6.0) - rspec-mocks (~> 3.6.0) - rspec-core (3.6.0) - rspec-support (~> 3.6.0) - rspec-expectations (3.6.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.6.0) - rspec-mocks (3.6.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.6.0) - rspec-support (3.6.0) - rubocop (0.47.1) - parser (>= 2.3.3.1, < 3.0) - powerpack (~> 0.1) - rainbow (>= 1.99.1, < 3.0) - ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.9.0) - safe_yaml (1.0.4) - unicode-display_width (1.3.0) - webmock (3.0.1) - addressable (>= 2.3.6) - crack (>= 0.3.2) - hashdiff - -PLATFORMS - ruby - -DEPENDENCIES - byebug - graphlient! - rake - rspec - rspec-mocks - rubocop (~> 0.47.1) - webmock - -BUNDLED WITH - 1.15.4 diff --git a/lib/graphlient/query.rb b/lib/graphlient/query.rb index 9acd869..2c32e54 100644 --- a/lib/graphlient/query.rb +++ b/lib/graphlient/query.rb @@ -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 diff --git a/spec/graphlient/query_spec.rb b/spec/graphlient/query_spec.rb index 22733e4..c371e6f 100644 --- a/spec/graphlient/query_spec.rb +++ b/spec/graphlient/query_spec.rb @@ -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