lib/fog/aliyun/models/storage/files.rb in fog-aliyun-0.3.0 vs lib/fog/aliyun/models/storage/files.rb in fog-aliyun-0.3.1
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
require 'fog/core/collection'
require 'fog/aliyun/models/storage/file'
module Fog
module Storage
@@ -13,25 +15,21 @@
model Fog::Storage::Aliyun::File
def all(_options = {})
requires :directory
- if directory.key != '' && directory.key != '.' && !directory.key.nil?
- prefix = directory.key + '/'
- end
+ prefix = directory.key + '/' if directory.key != '' && directory.key != '.' && !directory.key.nil?
files = service.list_objects(prefix: prefix)['Contents']
- return if nil == files
+ return if files.nil?
data = []
i = 0
files.each do |file|
next unless file['Key'][0][-1] != '/'
content_length = file['Size'][0].to_i
key = file['Key'][0]
lastModified = file['LastModified'][0]
- last_modified = if !lastModified.nil? && lastModified != ''
- Time.parse(lastModified).localtime
- end
+ last_modified = (Time.parse(lastModified).localtime if !lastModified.nil? && lastModified != '')
type = file['Type'][0]
data[i] = { content_length: content_length,
key: key,
last_modified: last_modified,
etag: file['ETag'][0],
@@ -65,17 +63,17 @@
key
else
directory.key + '/' + key
end
begin
- data = service.get_object(object)
- rescue => error
+ data = service.get_object(object)
+ rescue StandardError => error
case error.response.body
- when /<Code>NoSuchKey<\/Code>/
- nil
- else
- raise(error)
+ when /<Code>NoSuchKey<\/Code>/
+ nil
+ else
+ raise(error)
end
end
contentLen = data[:headers]['Content-Length'].to_i
@@ -94,13 +92,11 @@
else
body = data[:body]
end
lastModified = data[:headers]['Last-Modified']
- last_modified = if !lastModified.nil? && lastModified != ''
- Time.parse(lastModified).localtime
- end
+ last_modified = (Time.parse(lastModified).localtime if !lastModified.nil? && lastModified != '')
date = data[:headers]['Date']
date = (Time.parse(date).localtime if !date.nil? && date != '')
file_data = {
body: body,
@@ -157,12 +153,10 @@
else
directory.key + '/' + key
end
data = service.head_object(object).data
lastModified = data[:headers]['Last-Modified']
- last_modified = if !lastModified.nil? && lastModified != ''
- Time.parse(lastModified).localtime
- end
+ last_modified = (Time.parse(lastModified).localtime if !lastModified.nil? && lastModified != '')
date = data[:headers]['Date']
date = (Time.parse(date).localtime if !date.nil? && date != '')
file_data = {