Skip to content

Commit

Permalink
Add strong params extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured committed Mar 13, 2024
1 parent c6ad84a commit bac7f1a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions grape.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Gem::Specification.new do |s|
}

s.add_runtime_dependency 'activesupport', '>= 6'
s.add_runtime_dependency 'actionpack', '>= 6'
s.add_runtime_dependency 'builder'
s.add_runtime_dependency 'dry-types', '>= 1.1'
s.add_runtime_dependency 'mustermann-grape', '~> 1.1.0'
Expand Down
8 changes: 8 additions & 0 deletions lib/grape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,21 @@ module Extensions
eager_autoload do
autoload :Hash
end

module ActiveSupport
extend ::ActiveSupport::Autoload
eager_autoload do
autoload :HashWithIndifferentAccess
end
end

module ActionController
extend ::ActiveSupport::Autoload
eager_autoload do
autoload :Parameters
end
end

module Hashie
extend ::ActiveSupport::Autoload
eager_autoload do
Expand Down
27 changes: 27 additions & 0 deletions lib/grape/extensions/action_controller/parameters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Grape
module Extensions
module ActionController
class Parameters
module ParamBuilder
extend ::ActiveSupport::Concern

included do
namespace_inheritable(:build_params_with, Grape::Extensions::ActionController::Parameters::ParamBuilder)
end

def params_builder
Grape::Extensions::ActionController::Parameters::ParamBuilder
end

def build_params
::ActionController::Parameters.new(rack_params).tap do |params|
params.deep_merge!(grape_routing_args) if env.key?(Grape::Env::GRAPE_ROUTING_ARGS)
end
end
end
end
end
end
end

0 comments on commit bac7f1a

Please sign in to comment.