Skip to content

Commit

Permalink
Symbolize keys so we don't break Paperclip on Ruby 2.6
Browse files Browse the repository at this point in the history
Fixes fog#535
  • Loading branch information
Temikus committed Jul 30, 2021
1 parent 7e39340 commit 651d5cc
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 14 deletions.
4 changes: 3 additions & 1 deletion lib/fog/storage/google_json/models/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ def save

options[:predefined_acl] ||= @predefined_acl

service.put_object(directory.key, key, body, **options)
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
service.put_object(directory.key, key, body, **options.transform_keys(&:to_sym))
self.content_length = Fog::Storage.get_body_size(body)
self.content_type ||= Fog::Storage.get_content_type(body)
true
Expand Down
12 changes: 9 additions & 3 deletions lib/fog/storage/google_json/models/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def each

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

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

def metadata(key, options = {})
requires :directory
data = service.get_object_metadata(directory.key, key, **options).to_h
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
data = service.get_object_metadata(directory.key, key, **options.transform_keys(&:to_sym)).to_h
new(data)
rescue ::Google::Apis::ClientError
nil
Expand Down
4 changes: 3 additions & 1 deletion lib/fog/storage/google_json/requests/copy_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def copy_object(source_bucket, source_object,
target_bucket, target_object, options = {})
request_options = ::Google::Apis::RequestOptions.default.merge(options)

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

@storage_json.copy_object(source_bucket, source_object,
target_bucket, target_object,
Expand Down
4 changes: 3 additions & 1 deletion lib/fog/storage/google_json/requests/get_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def get_object(bucket_name, object_name,
if_metageneration_match: nil,
if_metageneration_not_match: nil,
projection: nil,
**options, &_block)
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
**options.transform_keys(&:to_sym), &_block)
raise ArgumentError.new("bucket_name is required") unless bucket_name
raise ArgumentError.new("object_name is required") unless object_name

Expand Down
8 changes: 6 additions & 2 deletions lib/fog/storage/google_json/requests/get_object_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ class Real
# Deprecated, redirects to get_object_https_url.rb
def get_object_url(bucket_name, object_name, expires, options = {})
Fog::Logger.deprecation("Fog::Storage::Google => #get_object_url is deprecated, use #get_object_https_url instead[/] [light_black](#{caller(0..0)})")
get_object_https_url(bucket_name, object_name, expires, **options)
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
get_object_https_url(bucket_name, object_name, expires, **options.transform_keys(&:to_sym))
end
end

class Mock # :nodoc:all
def get_object_url(bucket_name, object_name, expires, options = {})
Fog::Logger.deprecation("Fog::Storage::Google => #get_object_url is deprecated, use #get_object_https_url instead[/] [light_black](#{caller(0..0)})")
get_object_https_url(bucket_name, object_name, expires, **options)
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
get_object_https_url(bucket_name, object_name, expires, **options.transform_keys(&:to_sym))
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/fog/storage/google_json/requests/list_objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def list_objects(bucket, options = {})

@storage_json.list_objects(
bucket,
**options.select { |k, _| allowed_opts.include? k }
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
**options.transform_keys(&:to_sym).select { |k, _| allowed_opts.include? k }
)
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/fog/storage/google_json/requests/put_bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ class Real
def put_bucket(bucket_name,
predefined_acl: nil,
predefined_default_object_acl: nil,
**options)
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
**options.transform_keys(&:to_sym))
bucket = ::Google::Apis::StorageV1::Bucket.new(
**options.merge(:name => bucket_name)
**options.transform_keys(&:to_sym).merge(:name => bucket_name)
)

@storage_json.insert_bucket(
Expand Down
6 changes: 4 additions & 2 deletions lib/fog/storage/google_json/requests/put_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ def put_object(bucket_name,
if_metageneration_not_match: nil,
kms_key_name: nil,
predefined_acl: nil,
**options)
# **options.transform_keys(&:to_sym) is needed so paperclip doesn't break on Ruby 2.6
# TODO(temikus): remove this once Ruby 2.6 is deprecated for good
**options.transform_keys(&:to_sym))
data, options = normalize_data(data, options)

object_config = ::Google::Apis::StorageV1::Object.new(
**options.merge(:name => object_name)
**options.transform_keys(&:to_sym).merge(:name => object_name)
)

@storage_json.insert_object(
Expand Down
4 changes: 3 additions & 1 deletion lib/fog/storage/google_xml/models/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def save(options = {})
options["Expires"] = expires if expires
options.merge!(metadata)

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

0 comments on commit 651d5cc

Please sign in to comment.