-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Controller parameters wrapping feature
Required singleton for StrongParams wrapper Added comments
- Loading branch information
1 parent
977fe3c
commit 38dab69
Showing
7 changed files
with
101 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
lib/rage/controller/parameters_wrappers/parameters_wrapper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module ParametersWrappers | ||
class ParametersWrapper | ||
def initialize(wrapper_key, options) | ||
@wrapper_key = wrapper_key | ||
@options = options | ||
end | ||
|
||
def wrap_params(params) | ||
params.merge(wrapper_key => filtered_params(params)) | ||
end | ||
|
||
private | ||
|
||
attr_reader :wrapper_key, :options | ||
|
||
def filtered_params(params) | ||
if options[:include] | ||
params.slice(*[options[:include]].flatten) | ||
elsif options[:exclude] | ||
params.except(*[options[:exclude]].flatten) | ||
end | ||
end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
lib/rage/controller/parameters_wrappers/strong_parameters.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'singleton' | ||
|
||
module ParametersWrappers | ||
class StrongParameters | ||
include Singleton | ||
|
||
def wrap_params(params) | ||
ActionController::Parameters.new(params) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters