Class: Blouson::SensitiveParamsSilencer
- Inherits:
-
Object
- Object
- Blouson::SensitiveParamsSilencer
- Defined in:
- lib/blouson/sensitive_params_silencer.rb
Class Method Summary collapse
- .around(controller) ⇒ Object
- .include_sensitive_data?(controller) ⇒ Boolean
- .nested_params_keys(params) ⇒ Object
Class Method Details
.around(controller) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/blouson/sensitive_params_silencer.rb', line 4 def around(controller) if include_sensitive_data?(controller) begin old_level = ActiveRecord::Base.logger.level ActiveRecord::Base.logger.level = Logger::INFO Rails.logger.info " [Blouson::SensitiveParamsSilencer] SQL Log is skipped for sensitive data" yield ensure ActiveRecord::Base.logger.level = old_level end else yield end end |
.include_sensitive_data?(controller) ⇒ Boolean
19 20 21 |
# File 'lib/blouson/sensitive_params_silencer.rb', line 19 def include_sensitive_data?(controller) nested_params_keys(controller.params).any? { |key, value| Blouson::SENSITIVE_PARAMS_REGEXP === key } end |
.nested_params_keys(params) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/blouson/sensitive_params_silencer.rb', line 25 def nested_params_keys(params) if params.respond_to?(:to_unsafe_h) params = params.to_unsafe_h end user_params = params.reject { |key, value| 'controller' == key || 'action' == key } user_params.inject([]) do |keys, pair| keys << pair.first keys += pair.last.keys if pair.last.kind_of? Hash keys end end |