Skip to content

Commit

Permalink
do not collect params in route settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dnesteryuk committed Jan 5, 2022
1 parent cd7dd6a commit d52e1fc
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

* [#2222](https://github.com/ruby-grape/grape/pull/2222): Autoload types and validators - [@ericproulx](https://github.com/ericproulx).
* [#2232](https://github.com/ruby-grape/grape/pull/2232): Fix kwargs support in shared params definition - [@dm1try](https://github.com/dm1try).
* [#2229](https://github.com/ruby-grape/grape/pull/2229): Do not collect params in route settings - [@dnesteryuk](https://github.com/dnesteryuk).
* Your contribution here.

### 1.6.2 (2021/12/30)
Expand Down
1 change: 1 addition & 0 deletions benchmark/nested_params.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'grape'
require 'benchmark/ips'

Expand Down
15 changes: 0 additions & 15 deletions lib/grape/dsl/desc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,6 @@ def desc(description, options = {}, &config_block)
route_setting :description, options
end

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

def unset_description_field(field)
description = route_setting(:description)
description&.delete(field)
end

# Returns an object which configures itself via an instance-context DSL.
def desc_container(endpoint_configuration)
Module.new do
Expand Down
9 changes: 1 addition & 8 deletions lib/grape/dsl/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def reset_validations!
unset_namespace_stackable :declared_params
unset_namespace_stackable :validations
unset_namespace_stackable :params
unset_description_field :params
end

# Opens a root-level ParamsScope, defining parameter coercions and
Expand All @@ -41,14 +40,8 @@ def params(&block)
end

def document_attribute(names, opts)
setting = description_field(:params)
setting ||= description_field(:params, {})
Array(names).each do |name|
full_name = name[:full_name].to_s
setting[full_name] ||= {}
setting[full_name].merge!(opts)

namespace_stackable(:params, full_name => opts)
namespace_stackable(:params, name[:full_name].to_s => opts)
end
end
end
Expand Down
5 changes: 0 additions & 5 deletions spec/grape/dsl/validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ class Dummy
expect(subject.namespace_stackable(:params)).to eq []
end

it 'resets documentation params' do
expect(subject.route_setting(:description)[:params]).to be_nil
end

it 'does not reset documentation description' do
expect(subject.route_setting(:description)[:description]).to eq 'lol'
end
Expand All @@ -62,7 +58,6 @@ class Dummy

it 'creates a param documentation' do
expect(subject.namespace_stackable(:params)).to eq(['xxx' => { foo: 'bar' }])
expect(subject.route_setting(:description)).to eq(params: { 'xxx' => { foo: 'bar' } })
end
end
end
Expand Down

0 comments on commit d52e1fc

Please sign in to comment.