Class: Jets::Controller::ParametersFilter
- Inherits:
-
Object
- Object
- Jets::Controller::ParametersFilter
- Defined in:
- lib/jets/controller/parameters_filter.rb
Instance Attribute Summary collapse
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#params_filter ⇒ Object
readonly
Returns the value of attribute params_filter.
Instance Method Summary collapse
- #filter(params) ⇒ Object
- #filter_json(json_text) ⇒ Object
-
#initialize(filters) ⇒ ParametersFilter
constructor
A new instance of ParametersFilter.
Constructor Details
#initialize(filters) ⇒ ParametersFilter
Returns a new instance of ParametersFilter.
7 8 9 10 |
# File 'lib/jets/controller/parameters_filter.rb', line 7 def initialize(filters) @filters = filters @params_filter = ActiveSupport::ParameterFilter.new(filters) end |
Instance Attribute Details
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
5 6 7 |
# File 'lib/jets/controller/parameters_filter.rb', line 5 def filters @filters end |
#params_filter ⇒ Object (readonly)
Returns the value of attribute params_filter.
5 6 7 |
# File 'lib/jets/controller/parameters_filter.rb', line 5 def params_filter @params_filter end |
Instance Method Details
#filter(params) ⇒ Object
12 13 14 |
# File 'lib/jets/controller/parameters_filter.rb', line 12 def filter(params) params && params_filter.filter(params) end |
#filter_json(json_text) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/jets/controller/parameters_filter.rb', line 16 def filter_json(json_text) return json_text if filters.blank? || json_text.blank? begin hash_params = JSON.parse(json_text) filtered_params = filter(hash_params) JSON.dump(filtered_params) rescue JSON::ParserError String.new end end |