Skip to content

Commit

Permalink
Update all to_json_hash_value methods to take optional options
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Jan 7, 2020
1 parent 72bf456 commit 30ac31a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/protobuf/field/field_array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ def to_hash_value
# Return a hash-representation of the given values for this field type
# that is safe to convert to JSON.
# The value in this case would be an array.
def to_json_hash_value
def to_json_hash_value(options = {})
if field.respond_to?(:json_encode)
map do |value|
field.json_encode(value)
end
else
map do |value|
value.respond_to?(:to_json_hash_value) ? value.to_json_hash_value : value
value.respond_to?(:to_json_hash_value) ? value.to_json_hash_value(options) : value
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/protobuf/field/field_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ def to_hash_value
# The value in this case would be the hash itself, right? Unfortunately
# not because the values of the map could be messages themselves that we
# need to transform.
def to_json_hash_value
def to_json_hash_value(options = {})
if field.respond_to?(:json_encode)
each_with_object({}) do |(key, value), hash|
hash[key] = field.json_encode(value)
end
else
each_with_object({}) do |(key, value), hash|
hash[key] = value.respond_to?(:to_json_hash_value) ? value.to_json_hash_value : value
hash[key] = value.respond_to?(:to_json_hash_value) ? value.to_json_hash_value(options) : value
end
end
end
Expand Down

0 comments on commit 30ac31a

Please sign in to comment.