Skip to content

Commit 860c37b

Browse files
committed
Fix some rubocop issues
1 parent 5897a8e commit 860c37b

29 files changed

+78
-242
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ Naming/VariableName:
2929
Enabled: false
3030

3131
Lint/UnderscorePrefixedVariableName:
32+
Enabled: false
33+
34+
Metrics/LineLength:
3235
Enabled: false

.rubocop_todo.yml

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,6 @@
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 1
10-
# Cop supports --auto-correct.
11-
# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity.
12-
# SupportedStylesAlignWith: start_of_line, def
13-
Layout/DefEndAlignment:
14-
Exclude:
15-
- 'lib/fog/aliyun/requests/storage/put_object.rb'
16-
17-
# Offense count: 5
18-
# Cop supports --auto-correct.
19-
# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity.
20-
# SupportedStylesAlignWith: keyword, variable, start_of_line
21-
Layout/EndAlignment:
22-
Exclude:
23-
- 'lib/fog/aliyun/compute.rb'
24-
- 'lib/fog/aliyun/models/storage/file.rb'
25-
- 'lib/fog/aliyun/requests/compute/create_server.rb'
26-
- 'lib/fog/aliyun/storage.rb'
27-
289
# Offense count: 4
2910
# Configuration parameters: AllowSafeAssignment.
3011
Lint/AssignmentInCondition:
@@ -167,11 +148,3 @@ Style/MultipleComparison:
167148
Exclude:
168149
- 'lib/fog/aliyun/requests/storage/get_object_http_url.rb'
169150
- 'lib/fog/aliyun/requests/storage/get_object_https_url.rb'
170-
171-
# Offense count: 1
172-
# Cop supports --auto-correct.
173-
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
174-
# SupportedStyles: slashes, percent_r, mixed
175-
Style/RegexpLiteral:
176-
Exclude:
177-
- 'lib/fog/aliyun/models/storage/files.rb'

lib/fog/aliyun/compute.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,10 @@ def request(params)
313313
Fog::Compute::Aliyun::NotFound.slurp(error)
314314
else
315315
error
316-
end
316+
end
317317
end
318318

319-
if !response.body.empty? && response.get_header('Content-Type') == 'application/json'
320-
response.body = Fog::JSON.decode(response.body)
321-
end
319+
response.body = Fog::JSON.decode(response.body) if !response.body.empty? && response.get_header('Content-Type') == 'application/json'
322320

323321
response
324322
end
@@ -338,12 +336,10 @@ def VPCrequest(params)
338336
Fog::Compute::Aliyun::NotFound.slurp(error)
339337
else
340338
error
341-
end
339+
end
342340
end
343341

344-
if !response.body.empty? && response.get_header('Content-Type') == 'application/json'
345-
response.body = Fog::JSON.decode(response.body)
346-
end
342+
response.body = Fog::JSON.decode(response.body) if !response.body.empty? && response.get_header('Content-Type') == 'application/json'
347343

348344
response
349345
end

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ class File < Fog::Model
1919
attribute :object_type, aliases: 'x-oss-object-type'
2020

2121
def body
22-
attributes[:body] ||= if last_modified
23-
collection.get(identity).body
24-
else
25-
''
26-
end
22+
attributes[:body] ||=
23+
if last_modified
24+
collection.get(identity).body
25+
else
26+
''
27+
end
2728
end
2829

2930
def body=(new_body)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def get(key)
6868
data = service.get_object(object)
6969
rescue StandardError => error
7070
case error.response.body
71-
when /<Code>NoSuchKey<\/Code>/
71+
when %r{<Code>NoSuchKey</Code>}
7272
nil
7373
else
7474
raise(error)

lib/fog/aliyun/requests/compute/create_server.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,18 @@ def create_server(name, image_ref, flavor_ref, options = {})
105105
u.name == @openstack_username
106106
end
107107

108-
user_id = if user
109-
user.id
110-
else
111-
response = identity.create_user(@openstack_username,
112-
'password',
113-
"#{@openstack_username}@example.com")
114-
response.body['user']['id']
115-
end
108+
user_id =
109+
if user
110+
user.id
111+
else
112+
response =
113+
identity.create_user(
114+
@openstack_username,
115+
'password',
116+
"#{@openstack_username}@example.com"
117+
)
118+
response.body['user']['id']
119+
end
116120

117121
mock_data = {
118122
'addresses' => { 'Private' => [{ 'addr' => Fog::Mock.random_ip }] },

lib/fog/aliyun/requests/compute/join_security_group.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ def join_security_group(server_id, group_id)
2929
)
3030
end
3131
end
32-
33-
class Mock
34-
def join_security_group(_server_id, _group_id)
35-
response = Excon::Response.new
36-
response.status = 200
37-
response
38-
end
39-
end
4032
end
4133
end
4234
end

lib/fog/aliyun/requests/compute/leave_security_group.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ def leave_security_group(server_id, group_id)
2929
)
3030
end
3131
end
32-
33-
class Mock
34-
def add_security_group(_server_id, _group_name)
35-
response = Excon::Response.new
36-
response.status = 200
37-
response
38-
end
39-
end
4032
end
4133
end
4234
end

lib/fog/aliyun/requests/compute/list_server_types.rb

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@ def list_server_types
2121
method: 'GET',
2222
path: _pathURL
2323
)
24-
25-
# _InstanceType = Hash.new
26-
# _InstanceTypeList = Fog::JSON.decode(response.body)["InstanceTypes"]["InstanceType"]
27-
# _InstanceTypeList.each do |instanceType|
28-
# _InstanceType[[instanceType["CpuCoreCount"], instanceType["MemorySize"]]] = instanceType["InstanceTypeId"]
29-
# end
30-
# _InstanceType
31-
end list_server_types
24+
end
3225

3326
def get_instance_type(cpuCount, memorySize)
3427
_action = 'DescribeInstanceTypes'
@@ -49,31 +42,15 @@ def get_instance_type(cpuCount, memorySize)
4942

5043
_InstanceTypeId = nil
5144
_InstanceTypeList = Fog::JSON.decode(response.body)['InstanceTypes']['InstanceType']
52-
_InstanceTypeList.each do |instanceType|
53-
next unless (instanceType['CpuCoreCount'] == cpuCount) && (instanceType['MemorySize'] == memorySize)
54-
_InstanceTypeId = instanceType['InstanceTypeId']
45+
_InstanceTypeList.each do |instance_type|
46+
next unless (instance_type['CpuCoreCount'] == cpuCount) && (instance_type['MemorySize'] == memorySize)
47+
_InstanceTypeId = instance_type['InstanceTypeId']
5548
puts '_instanceTypeId: ' + _InstanceTypeId
5649
break
57-
# end if
58-
end each
50+
end
5951
_InstanceTypeId
60-
end get_instance_type
61-
end class Real
62-
63-
# class Mock
64-
# def list_servers(options = {})
65-
# response = Excon::Response.new
66-
# data = list_servers_detail.body['servers']
67-
# servers = []
68-
# for server in data
69-
# servers << server.reject { |key, value| !['id', 'name', 'links'].include?(key) }
70-
# end
71-
# response.status = [200, 203][rand(1)]
72-
# response.body = { 'servers' => servers }
73-
# response
74-
# end
75-
# end
76-
end class Aliyun
77-
end module Compute
78-
# end module Fog
52+
end
53+
end
54+
end
55+
end
7956
end

lib/fog/aliyun/requests/compute/reboot_server.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ def reboot_server(server_id, options = {})
3232
)
3333
end
3434
end
35-
36-
class Mock
37-
def reboot_server(_server_id, _type = 'SOFT')
38-
response = Excon::Response.new
39-
response.status = 202
40-
response
41-
end
42-
end
4335
end
4436
end
4537
end

0 commit comments

Comments
 (0)