Skip to content

Commit

Permalink
Bump representable dependency to 3.0 (googleapis#532)
Browse files Browse the repository at this point in the history
Also fixes a breaking change introduced between `representable` 2.3 and
3.0. Specifically, `:skip_undefined` is now be passed via the
`:user_options` option.
  • Loading branch information
saicheems authored Feb 13, 2017
1 parent 2ea7f12 commit 4f143ae
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ rvm:
- 2.0.0
- jruby-9000
env:
- RAILS_VERSION="~>3.2"
- RAILS_VERSION="~>4.0.0"
- RAILS_VERSION="~>4.1.0"
- RAILS_VERSION="~>4.2.0"
global:
- JRUBY_OPTS='-X-C -J-Xmx1024m -J-XX:+UseConcMarkSweepGC'
matrix:
- RAILS_VERSION="~>3.2"
- RAILS_VERSION="~>4.0.0"
- RAILS_VERSION="~>4.1.0"
- RAILS_VERSION="~>4.2.0"
matrix:
exclude:
- rvm: 2.0.0
Expand Down
2 changes: 1 addition & 1 deletion google-api-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = '~> 2.0'

spec.add_runtime_dependency 'representable', '~> 2.3.0'
spec.add_runtime_dependency 'representable', '~> 3.0'
spec.add_runtime_dependency 'retriable', '>= 2.0', '< 4.0'
spec.add_runtime_dependency 'addressable', '~> 2.3'
spec.add_runtime_dependency 'mime-types', '>= 1.6'
Expand Down
2 changes: 1 addition & 1 deletion lib/google/apis/core/api_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def prepare!
query[FIELDS_PARAM] = normalize_fields_param(query[FIELDS_PARAM]) if query.key?(FIELDS_PARAM)
if request_representation && request_object
header[:content_type] ||= JSON_CONTENT_TYPE
self.body = request_representation.new(request_object).to_json(skip_undefined: true)
self.body = request_representation.new(request_object).to_json(user_options: { skip_undefined: true })
end
super
end
Expand Down
4 changes: 2 additions & 2 deletions lib/google/apis/core/json_representation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def getter_fn(name)
def if_fn(name)
ivar_name = "@#{name}".to_sym
lambda do |opts|
if opts[:skip_undefined]
if opts[:options][:user_options] and opts[:options][:user_options][:skip_undefined]
if respond_to?(:key?)
self.key?(name) || instance_variable_defined?(ivar_name)
else
Expand Down Expand Up @@ -137,7 +137,7 @@ def from_json(json)

def to_json
representation = self.class.const_get(:Representation)
representation.new(self).to_json(skip_undefined: true)
representation.new(self).to_json(user_options: { skip_undefined: true })
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/google/apis/core/json_representation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
end

context 'with model object' do
let(:json) { representer_class.new(model).to_json(skip_undefined: true) }
let(:json) { representer_class.new(model).to_json(user_options: { skip_undefined: true }) }
let(:model) do
model = model_class.new
model.nil_value = nil
Expand All @@ -132,7 +132,7 @@
end

context 'with hash' do
let(:json) { representer_class.new(model).to_json(skip_undefined: true) }
let(:json) { representer_class.new(model).to_json(user_options: { skip_undefined: true }) }
let(:model) do
{
nil_value: nil,
Expand Down

0 comments on commit 4f143ae

Please sign in to comment.