Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
Fix JSON print in Ruby (#1274)
Browse files Browse the repository at this point in the history
It turns out that `to_h` is not a method available on every object
returned by the samples at the moment. Also, there's some kind of
decoding bug showing up in certain samples where the JSON module is
unable to unparse the response.

It's troublesome to have so much boilerplate just to pretty print. This
commit removes the pretty calls in favor of the vanilla `to_json` method
implemented by the base model class in the Ruby client. In the future,
once the bugs w.r.t `pretty_generate` have been resolved, we can revert.
  • Loading branch information
saicheems authored May 18, 2017
1 parent daa59cd commit 50754f0
Show file tree
Hide file tree
Showing 29 changed files with 807 additions and 1,614 deletions.
9 changes: 3 additions & 6 deletions src/main/resources/com/google/api/codegen/ruby/sample.snip
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
require 'googleauth'
@end
require '{@class.serviceRequirePath}'
@if class.hasResponse
require 'json'
@end

{@class.serviceVarName} = {@class.serviceTypeNamespace}::{@class.serviceTypeName}.new

Expand Down Expand Up @@ -116,22 +113,22 @@
@if class.pageStreaming.isResourceMap
{@class.pageStreaming.pageVarName}.each do |{@class.pageStreaming.resourceKeyVarName}, {@class.pageStreaming.resourceValueVarName}|
@# TODO: Change code below to process each ({@class.pageStreaming.resourceKeyVarName}, {@class.pageStreaming.resourceValueVarName}) pair:
puts String({@class.pageStreaming.resourceKeyVarName} << " => " << JSON.pretty_unparse({@class.pageStreaming.resourceValueVarName}.to_h)
puts String({@class.pageStreaming.resourceKeyVarName} << " => " << {@class.pageStreaming.resourceValueVarName}.to_json
end
@else
# We don't handle non-repeated page streaming resources separately in Ruby
# because the fetch_all treats them correctly.
{@class.pageStreaming.pageVarName}.each do |{@class.pageStreaming.resourceVarName}|
@# TODO: Change code below to process each `{@class.pageStreaming.resourceVarName}` resource:
puts JSON.pretty_unparse({@class.pageStreaming.resourceVarName}.to_h)
puts {@class.pageStreaming.resourceVarName}.to_json
end
@end
@else
@if class.hasResponse
{@class.responseVarName} = {@methodCall(class)}({@paramList(class.methodCallFieldVarNames)})

@# TODO: Change code below to process the `{@class.responseVarName}` object:
puts JSON.pretty_unparse({@class.responseVarName}.to_h)
puts {@class.responseVarName}.to_json
@else
{@methodCall(class)}({@paramList(class.methodCallFieldVarNames)})
@end
Expand Down
Loading

0 comments on commit 50754f0

Please sign in to comment.