Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style/CaseLikeIf-20221003233959 #795

Merged
merged 4 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1323,15 +1323,6 @@ Style/CaseEquality:
Exclude:
- 'lib/apipie/validator.rb'

# Offense count: 5
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/CaseLikeIf:
Exclude:
- 'lib/apipie/dsl_definition.rb'
- 'lib/apipie/extractor/writer.rb'
- 'lib/apipie/response_description_adapter.rb'
- 'spec/controllers/users_controller_spec.rb'

# Offense count: 11
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
Expand Down Expand Up @@ -1508,13 +1499,12 @@ Style/For:
Style/FrozenStringLiteralComment:
Enabled: false

# Offense count: 36
# Offense count: 35
# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
Style/GuardClause:
Exclude:
- 'app/controllers/apipie/apipies_controller.rb'
- 'lib/apipie/application.rb'
- 'lib/apipie/dsl_definition.rb'
- 'lib/apipie/extractor.rb'
- 'lib/apipie/extractor/collector.rb'
- 'lib/apipie/extractor/writer.rb'
Expand Down
5 changes: 3 additions & 2 deletions lib/apipie/dsl_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,10 @@ def _apipie_define_validators(description)
end

def _apipie_handle_validate_key_error params, param
if Apipie.configuration.action_on_non_validated_keys == :raise
case Apipie.configuration.action_on_non_validated_keys
when :raise
raise UnknownParam, param
elsif Apipie.configuration.action_on_non_validated_keys == :skip
when :skip
params.delete(param)
Rails.logger.warn(UnknownParam.new(param).to_s)
end
Expand Down
5 changes: 3 additions & 2 deletions lib/apipie/extractor/writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ def ordered_call(call)

def convert_file_value hash
hash.each do |k, v|
if v.is_a?(Rack::Test::UploadedFile) || v.is_a?(ActionDispatch::Http::UploadedFile)
case v
when Rack::Test::UploadedFile, ActionDispatch::Http::UploadedFile
hash[k] = "<FILE CONTENT '#{v.original_filename}'>"
elsif v.is_a?(Hash)
when Hash
hash[k] = convert_file_value(v)
end
end
Expand Down
10 changes: 6 additions & 4 deletions lib/apipie/response_description_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ def [](key)

def add_sub_property(prop_desc)
raise "Only properties with expected_type 'object' can have sub-properties" unless @expected_type == 'object'
if prop_desc.is_a? PropDesc
case prop_desc
when PropDesc
@sub_properties << prop_desc
elsif prop_desc.is_a? Modifier
when Modifier
prop_desc.apply(self)
else
raise "Unrecognized prop_desc type (#{prop_desc.class})"
Expand Down Expand Up @@ -170,9 +171,10 @@ def to_json
end

def add(prop_desc)
if prop_desc.is_a? PropDesc
case prop_desc
when PropDesc
@property_descs << prop_desc
elsif prop_desc.is_a? Modifier
when Modifier
prop_desc.apply(self)
else
raise "Unrecognized prop_desc type (#{prop_desc.class})"
Expand Down
5 changes: 3 additions & 2 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ def compare_hashes(h1, h2)
expect(h1).to eq(h2)
else
h1.each do |key, val|
if val.is_a? Hash
case val
when Hash
compare_hashes val, h2[key]
elsif val.is_a? Array
when Array
val.each_with_index do |v, i|
compare_hashes val[i], h2[key][i]
end
Expand Down