Skip to content

Commit 4e542d2

Browse files
committed
nitpick: rubocop fixes && refactor
1 parent f91eaf0 commit 4e542d2

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

lib/microcms.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def ==(other)
4141
end
4242

4343
def to_h
44-
@data.transform_values { |value|
44+
@data.transform_values do |value|
4545
case value
4646
when ResponseObject
4747
value.to_h
@@ -50,7 +50,7 @@ def to_h
5050
else
5151
value
5252
end
53-
}
53+
end
5454
end
5555

5656
def [](key)
@@ -63,7 +63,7 @@ def []=(key, value)
6363

6464
def method_missing(method_name, *args, &block)
6565
method_str = method_name.to_s
66-
66+
6767
if method_str.end_with?('=')
6868
key = method_str.chomp('=').to_sym
6969
@data[key] = convert_value(args.first)
@@ -153,7 +153,7 @@ def build_uri(endpoint, path, query)
153153
origin = "https://#{@service_domain}.microcms.io"
154154
path_with_id = path ? "/api/v1/#{endpoint}/#{path}" : "/api/v1/#{endpoint}"
155155
encoded_query =
156-
if !query || query.size.zero?
156+
if !query || query.empty?
157157
''
158158
else
159159
"?#{URI.encode_www_form(query)}"
@@ -211,7 +211,7 @@ def get(endpoint, id = '', option = {})
211211
id,
212212
{
213213
draftKey: option[:draft_key],
214-
fields: option[:fields] ? option[:fields].join(',') : nil,
214+
fields: option[:fields]&.join(','),
215215
depth: option[:depth]
216216
}.select { |_key, value| value }
217217
)
@@ -226,7 +226,7 @@ def create(endpoint, content, option = {})
226226
end
227227

228228
def update(endpoint, content)
229-
body = content.reject { |key, _value| key == :id }
229+
body = content.except(:id)
230230
send_http_request('PATCH', endpoint, content[:id], nil, body)
231231
end
232232

@@ -242,18 +242,18 @@ def build_query(option)
242242
draftKey: option[:draftKey],
243243
limit: option[:limit],
244244
offset: option[:offset],
245-
orders: option[:orders] ? option[:orders].join(',') : nil,
245+
orders: option[:orders]&.join(','),
246246
q: option[:q],
247-
fields: option[:fields] ? option[:fields].join(',') : nil,
247+
fields: option[:fields]&.join(','),
248248
filters: option[:filters],
249249
depth: option[:depth],
250-
ids: option[:ids] ? option[:ids].join(',') : nil
250+
ids: option[:ids]&.join(',')
251251
}.select { |_key, value| value }
252252
end
253253
# rubocop:enable Style/MethodLength
254254

255255
def put(endpoint, content, option = {})
256-
body = content.reject { |key, _value| key == :id }
256+
body = content.except(:id)
257257
send_http_request('PUT', endpoint, content[:id], option, body)
258258
end
259259

microcms.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
1010
spec.summary = 'microCMS Ruby SDK'
1111
spec.description = 'microCMS Ruby SDK'
1212
spec.homepage = 'https://github.com/microcmsio/microcms-ruby-sdk'
13-
spec.required_ruby_version = Gem::Requirement.new('>= 3.4.4')
13+
spec.required_ruby_version = Gem::Requirement.new('>= 3.0')
1414

1515
spec.metadata['homepage_uri'] = spec.homepage
1616
spec.metadata['source_code_uri'] = spec.homepage

spec/microcms_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
it 'raises MicroCMS::APIError' do
181181
expect_any_instance_of(Net::HTTP).to receive(:request).and_return(mock_client_error_response)
182182
expect { client.create('endpoint', { id: 'bar', baz: 'quux' }) }.to(
183-
raise_error(an_instance_of(::MicroCMS::APIError)
183+
raise_error(an_instance_of(MicroCMS::APIError)
184184
.and(have_attributes({
185185
status_code: 400,
186186
message: 'client error',
@@ -195,7 +195,7 @@
195195
expect_any_instance_of(Net::HTTP).to receive(:request).and_return(mock_server_error_response)
196196

197197
expect { client.create('endpoint', { id: 'bar', baz: 'quux' }) }.to(
198-
raise_error(an_instance_of(::MicroCMS::APIError)
198+
raise_error(an_instance_of(MicroCMS::APIError)
199199
.and(have_attributes({
200200
status_code: 500,
201201
message: 'server error',

test_response_object.rb

100644100755
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
23

34
# Simple test to verify ResponseObject functionality
45
require_relative 'lib/microcms'
56

67
# Test ResponseObject creation and access
7-
puts "Testing ResponseObject..."
8+
puts 'Testing ResponseObject...'
89

910
# Test 1: Basic creation and access
1011
response = MicroCMS::ResponseObject.new({ id: 'test123', name: 'Test Article' })
@@ -18,7 +19,7 @@
1819
id: 'author1',
1920
name: 'John Doe'
2021
},
21-
tags: ['ruby', 'programming']
22+
tags: %w[ruby programming]
2223
}
2324

2425
nested_response = MicroCMS::ResponseObject.new(nested_data)

0 commit comments

Comments
 (0)