Skip to content

Commit 92caf4c

Browse files
authored
Remove unused codes (#162)
* Remove unused codes Now that we support Ruby 2.7 and above, we can remove conditions with versions lower than that. * Replace String#match with String#match? `String#match?` is more suitable when only a boolean is needed, as it is faster than `String#match`. OpenapiParser now supports Ruby2.7 and above, and since `String#match?` has been available since Ruby2.4, it’s appropriate to make this switch.
1 parent 7ff08bb commit 92caf4c

File tree

4 files changed

+8
-35
lines changed

4 files changed

+8
-35
lines changed

lib/openapi_parser.rb

+2-5
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,11 @@ def parse_file(content, ext)
8181
end
8282

8383
def parse_yaml(content)
84-
# FIXME: when drop ruby 2.5, we should use permitted_classes
85-
(Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.6.0")) ?
86-
Psych.safe_load(content, [Date, Time]) :
87-
Psych.safe_load(content, permitted_classes: [Date, Time])
84+
Psych.safe_load(content, permitted_classes: [Date, Time])
8885
end
8986

9087
def parse_json(content)
91-
raise "json content is nil" unless content
88+
raise "json content is nil" unless content
9289
JSON.parse(content)
9390
end
9491

lib/openapi_parser/schema_validator/string_validator.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ def validate_max_min_length(value, schema)
5555
def validate_email_format(value, schema)
5656
return [value, nil] unless schema.format == 'email'
5757

58-
# match? method is good performance.
59-
# So when we drop ruby 2.3 support we use match? method because this method add ruby 2.4
60-
#return [value, nil] if value.match?(URI::MailTo::EMAIL_REGEXP)
61-
return [value, nil] if value.match(URI::MailTo::EMAIL_REGEXP)
58+
return [value, nil] if value.match?(URI::MailTo::EMAIL_REGEXP)
6259

6360
return [nil, OpenAPIParser::InvalidEmailFormat.new(value, schema.object_reference)]
6461
end

spec/openapi_parser/request_operation_spec.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@
110110
it do
111111
expect { subject }.to raise_error do |e|
112112
expect(e).to be_kind_of(OpenAPIParser::ValidateError)
113-
if Gem::Version.create(RUBY_VERSION) <= Gem::Version.create('2.4.0')
114-
expect(e.message).to end_with("expected string, but received Fixnum: 1")
115-
else
116-
expect(e.message).to end_with("expected string, but received Integer: 1")
117-
end
113+
expect(e.message).to end_with("expected string, but received Integer: 1")
118114
end
119115
end
120116
end

spec/openapi_parser/schema_validator_spec.rb

+4-21
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,7 @@
571571
nested_array = params['nested_array']
572572
first_data = nested_array[0]
573573
expect(first_data['update_time'].class).to eq DateTime
574-
575-
if Gem::Version.create(RUBY_VERSION) <= Gem::Version.create('2.4.0')
576-
expect(first_data['per_page'].class).to eq Fixnum # rubocop:disable Lint/UnifiedInteger
577-
else
578-
expect(first_data['per_page'].class).to eq Integer
579-
end
574+
expect(first_data['per_page'].class).to eq Integer
580575
end
581576
end
582577

@@ -774,27 +769,15 @@
774769
nested_array = params['nested_array']
775770
first_data = nested_array[0]
776771
expect(first_data['update_time'].class).to eq String
777-
if Gem::Version.create(RUBY_VERSION) <= Gem::Version.create('2.4.0')
778-
expect(first_data['per_page'].class).to eq Fixnum # rubocop:disable Lint/UnifiedInteger
779-
else
780-
expect(first_data['per_page'].class).to eq Integer
781-
end
772+
expect(first_data['per_page'].class).to eq Integer
782773

783774
second_data = nested_array[1]
784775
expect(second_data['update_time'].class).to eq String
785-
if Gem::Version.create(RUBY_VERSION) <= Gem::Version.create('2.4.0')
786-
expect(first_data['per_page'].class).to eq Fixnum # rubocop:disable Lint/UnifiedInteger
787-
else
788-
expect(first_data['per_page'].class).to eq Integer
789-
end
776+
expect(first_data['per_page'].class).to eq Integer
790777
expect(second_data['threshold'].class).to eq Float
791778

792779
third_data = nested_array[2]
793-
if Gem::Version.create(RUBY_VERSION) <= Gem::Version.create('2.4.0')
794-
expect(first_data['per_page'].class).to eq Fixnum # rubocop:disable Lint/UnifiedInteger
795-
else
796-
expect(first_data['per_page'].class).to eq Integer
797-
end
780+
expect(first_data['per_page'].class).to eq Integer
798781
expect(third_data['threshold'].class).to eq Float
799782

800783
expect(first_data['nested_coercer_object']['update_time'].class).to eq String

0 commit comments

Comments
 (0)