Skip to content

Commit

Permalink
Merge pull request #1837 from dblock/freeze
Browse files Browse the repository at this point in the history
Freeze the result of the call + some rubocop offenses.
  • Loading branch information
myxoh committed Dec 7, 2018
2 parents aabb722 + 99d5ec7 commit 34610f5
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 66 deletions.
51 changes: 2 additions & 49 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-11-22 00:04:22 +0900 using RuboCop version 0.51.0.
# on 2018-12-06 21:06:59 -0500 using RuboCop version 0.51.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -16,10 +16,9 @@ Layout/IndentHeredoc:
- 'spec/grape/api_spec.rb'
- 'spec/grape/entity_spec.rb'

# Offense count: 2
# Offense count: 1
Lint/AmbiguousBlockAssociation:
Exclude:
- 'lib/grape/middleware/stack.rb'
- 'spec/grape/dsl/routing_spec.rb'

# Offense count: 1
Expand Down Expand Up @@ -75,54 +74,8 @@ Naming/FileName:
- 'Guardfile'
- 'Rakefile'

# Offense count: 1
# Configuration parameters: Blacklist.
# Blacklist: END, (?-mix:EO[A-Z]{1})
Naming/HeredocDelimiterNaming:
Exclude:
- 'lib/grape/router/route.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect.
Performance/HashEachMethods:
Exclude:
- 'lib/grape/api/instance.rb'
- 'lib/grape/middleware/versioner/header.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'spec/grape/middleware/formatter_spec.rb'

# Offense count: 1
Style/CommentedKeyword:
Exclude:
- 'spec/grape/validations_spec.rb'

# Offense count: 2
# Configuration parameters: SupportedStyles.
# SupportedStyles: annotated, template
Style/FormatStringToken:
EnforcedStyle: template

# Offense count: 2
Style/IdenticalConditionalBranches:
Exclude:
- 'lib/grape/dsl/desc.rb'

# Offense count: 1
Style/MethodMissing:
Exclude:
- 'lib/grape/router/attribute_translator.rb'

# Offense count: 1
Style/MultipleComparison:
Exclude:
- 'lib/grape/validations/types/custom_type_coercer.rb'
2 changes: 1 addition & 1 deletion lib/grape/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Grape
# should subclass this class in order to build an API.
class API
# Class methods that we want to call on the API rather than on the API object
NON_OVERRIDABLE = Class.new.methods.freeze + %i[call call!]
NON_OVERRIDABLE = (Class.new.methods + %i[call call!]).freeze

class << self
attr_accessor :base_instance, :instances
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/api/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def add_head_not_allowed_methods_and_options_methods
# informations again.
without_root_prefix do
without_versioning do
routes_map.each do |_, config|
routes_map.each_value do |config|
methods = config[:methods]
allowed_methods = methods.dup

Expand Down
7 changes: 3 additions & 4 deletions lib/grape/dsl/desc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ def desc(description, options = {}, &config_block)
end

def description_field(field, value = nil)
description = route_setting(:description)
if value
description = route_setting(:description)
description ||= route_setting(:description, {})
description[field] = value
else
description = route_setting(:description)
description[field] if description
elsif description
description[field]
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/grape/middleware/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def build(builder = Rack::Builder.new)
# @param [Array] other_specs An array of middleware specifications (e.g. [[:use, klass], [:insert_before, *args]])
def concat(other_specs)
@others << Array(other_specs).reject { |o| o.first == :use }
merge_with Array(other_specs).select { |o| o.first == :use }
merge_with(Array(other_specs).select { |o| o.first == :use })
end

protected
Expand Down
4 changes: 2 additions & 2 deletions lib/grape/middleware/versioner/header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def fail_with_invalid_version_header!(message)
def available_media_types
available_media_types = []

content_types.each do |extension, _media_type|
content_types.each_key do |extension|
versions.reverse_each do |version|
available_media_types += [
"application/vnd.#{vendor}-#{version}+#{extension}",
Expand All @@ -111,7 +111,7 @@ def available_media_types

available_media_types << "application/vnd.#{vendor}"

content_types.each do |_, media_type|
content_types.each_value do |media_type|
available_media_types << media_type
end

Expand Down
2 changes: 2 additions & 0 deletions lib/grape/router/attribute_translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def method_missing(m, *args)
@attributes[m[0..-1]] = *args
elsif m[-1] != '='
@attributes[m]
else
super
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/grape/router/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def warn_route_methods(name, location, expected = nil)
path, line = *location.scan(SOURCE_LOCATION_REGEXP).first
path = File.realpath(path) if Pathname.new(path).relative?
expected ||= name
warn <<-EOS
warn <<-WARNING
#{path}:#{line}: The route_xxx methods such as route_#{name} have been deprecated, please use #{expected}.
EOS
WARNING
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/validations/types/custom_type_coercer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def infer_type_check(type)
# necessary.
def enforce_symbolized_keys(type, method)
# Collections have all values processed individually
if type == Array || type == Set
if [Array, Set].include?(type)
lambda do |val|
method.call(val).tap do |new_value|
new_value.map do |item|
Expand Down
8 changes: 4 additions & 4 deletions spec/grape/middleware/formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ def to_xml
let(:content_type) { 'application/atom+xml' }

it 'returns a 415 HTTP error status' do
error = catch(:error) {
error = catch(:error) do
subject.call(
'PATH_INFO' => '/info',
'REQUEST_METHOD' => method,
'CONTENT_TYPE' => content_type,
'rack.input' => io,
'CONTENT_LENGTH' => io.length
)
}
end
expect(error[:status]).to eq(415)
expect(error[:message]).to eq("The provided content-type 'application/atom+xml' is not supported.")
end
Expand Down Expand Up @@ -407,15 +407,15 @@ def self.call(_, _)
parsers: { json: ->(_object, _env) { raise StandardError, 'fail' } }
)
io = StringIO.new('{invalid}')
error = catch(:error) {
error = catch(:error) do
subject.call(
'PATH_INFO' => '/info',
'REQUEST_METHOD' => 'POST',
'CONTENT_TYPE' => 'application/json',
'rack.input' => io,
'CONTENT_LENGTH' => io.length
)
}
end

expect(error[:message]).to eq 'fail'
expect(error[:backtrace].size).to be >= 1
Expand Down
2 changes: 1 addition & 1 deletion spec/grape/validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ def validate_param!(attr_name, params)
expect(last_response.body).to eq('custom is not custom with options!')
end
end
end # end custom validation
end

context 'named' do
context 'can be defined' do
Expand Down

0 comments on commit 34610f5

Please sign in to comment.