Skip to content

Commit 651d5cc

Browse files
committed
Symbolize keys so we don't break Paperclip on Ruby 2.6
Fixes fog#535
1 parent 7e39340 commit 651d5cc

File tree

9 files changed

+38
-14
lines changed

9 files changed

+38
-14
lines changed

lib/fog/storage/google_json/models/file.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ def save
105105

106106
options[:predefined_acl] ||= @predefined_acl
107107

108-
service.put_object(directory.key, key, body, **options)
108+
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
109+
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
110+
service.put_object(directory.key, key, body, **options.transform_keys(&:to_sym))
109111
self.content_length = Fog::Storage.get_body_size(body)
110112
self.content_type ||= Fog::Storage.get_content_type(body)
111113
true

lib/fog/storage/google_json/models/files.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def each
3333

3434
def get(key, options = {}, &block)
3535
requires :directory
36-
data = service.get_object(directory.key, key, **options, &block).to_h
36+
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
37+
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
38+
data = service.get_object(directory.key, key, **options.transform_keys(&:to_sym), &block).to_h
3739
new(data)
3840
rescue ::Google::Apis::ClientError => e
3941
raise e unless e.status_code == 404
@@ -42,12 +44,16 @@ def get(key, options = {}, &block)
4244

4345
def get_https_url(key, expires, options = {})
4446
requires :directory
45-
service.get_object_https_url(directory.key, key, expires, **options)
47+
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
48+
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
49+
service.get_object_https_url(directory.key, key, expires, **options.transform_keys(&:to_sym))
4650
end
4751

4852
def metadata(key, options = {})
4953
requires :directory
50-
data = service.get_object_metadata(directory.key, key, **options).to_h
54+
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
55+
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
56+
data = service.get_object_metadata(directory.key, key, **options.transform_keys(&:to_sym)).to_h
5157
new(data)
5258
rescue ::Google::Apis::ClientError
5359
nil

lib/fog/storage/google_json/requests/copy_object.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ def copy_object(source_bucket, source_object,
1515
target_bucket, target_object, options = {})
1616
request_options = ::Google::Apis::RequestOptions.default.merge(options)
1717

18-
object = ::Google::Apis::StorageV1::Object.new(**options)
18+
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
19+
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
20+
object = ::Google::Apis::StorageV1::Object.new(**options.transform_keys(&:to_sym))
1921

2022
@storage_json.copy_object(source_bucket, source_object,
2123
target_bucket, target_object,

lib/fog/storage/google_json/requests/get_object.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def get_object(bucket_name, object_name,
3434
if_metageneration_match: nil,
3535
if_metageneration_not_match: nil,
3636
projection: nil,
37-
**options, &_block)
37+
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
38+
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
39+
**options.transform_keys(&:to_sym), &_block)
3840
raise ArgumentError.new("bucket_name is required") unless bucket_name
3941
raise ArgumentError.new("object_name is required") unless object_name
4042

lib/fog/storage/google_json/requests/get_object_url.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ class Real
66
# Deprecated, redirects to get_object_https_url.rb
77
def get_object_url(bucket_name, object_name, expires, options = {})
88
Fog::Logger.deprecation("Fog::Storage::Google => #get_object_url is deprecated, use #get_object_https_url instead[/] [light_black](#{caller(0..0)})")
9-
get_object_https_url(bucket_name, object_name, expires, **options)
9+
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
10+
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
11+
get_object_https_url(bucket_name, object_name, expires, **options.transform_keys(&:to_sym))
1012
end
1113
end
1214

1315
class Mock # :nodoc:all
1416
def get_object_url(bucket_name, object_name, expires, options = {})
1517
Fog::Logger.deprecation("Fog::Storage::Google => #get_object_url is deprecated, use #get_object_https_url instead[/] [light_black](#{caller(0..0)})")
16-
get_object_https_url(bucket_name, object_name, expires, **options)
18+
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
19+
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
20+
get_object_https_url(bucket_name, object_name, expires, **options.transform_keys(&:to_sym))
1721
end
1822
end
1923
end

lib/fog/storage/google_json/requests/list_objects.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def list_objects(bucket, options = {})
3131

3232
@storage_json.list_objects(
3333
bucket,
34-
**options.select { |k, _| allowed_opts.include? k }
34+
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
35+
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
36+
**options.transform_keys(&:to_sym).select { |k, _| allowed_opts.include? k }
3537
)
3638
end
3739
end

lib/fog/storage/google_json/requests/put_bucket.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ class Real
1717
def put_bucket(bucket_name,
1818
predefined_acl: nil,
1919
predefined_default_object_acl: nil,
20-
**options)
20+
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
21+
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
22+
**options.transform_keys(&:to_sym))
2123
bucket = ::Google::Apis::StorageV1::Bucket.new(
22-
**options.merge(:name => bucket_name)
24+
**options.transform_keys(&:to_sym).merge(:name => bucket_name)
2325
)
2426

2527
@storage_json.insert_bucket(

lib/fog/storage/google_json/requests/put_object.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ def put_object(bucket_name,
4747
if_metageneration_not_match: nil,
4848
kms_key_name: nil,
4949
predefined_acl: nil,
50-
**options)
50+
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
51+
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
52+
**options.transform_keys(&:to_sym))
5153
data, options = normalize_data(data, options)
5254

5355
object_config = ::Google::Apis::StorageV1::Object.new(
54-
**options.merge(:name => object_name)
56+
**options.transform_keys(&:to_sym).merge(:name => object_name)
5557
)
5658

5759
@storage_json.insert_object(

lib/fog/storage/google_xml/models/file.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ def save(options = {})
109109
options["Expires"] = expires if expires
110110
options.merge!(metadata)
111111

112-
data = service.put_object(directory.key, key, body, **options)
112+
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
113+
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
114+
data = service.put_object(directory.key, key, body, **options.transform_keys(&:to_sym))
113115
merge_attributes(data.headers.reject { |key, _value| ["Content-Length", "Content-Type"].include?(key) })
114116
self.content_length = Fog::Storage.get_body_size(body)
115117
self.content_type ||= Fog::Storage.get_content_type(body)

0 commit comments

Comments
 (0)