Class: Readme::Filter::AllowOnly
- Inherits:
-
Object
- Object
- Readme::Filter::AllowOnly
- Defined in:
- lib/readme/filter.rb
Instance Method Summary collapse
- #filter(hash) ⇒ Object
-
#initialize(filter_fields) ⇒ AllowOnly
constructor
A new instance of AllowOnly.
- #pass_through? ⇒ Boolean
Constructor Details
#initialize(filter_fields) ⇒ AllowOnly
Returns a new instance of AllowOnly.
23 24 25 |
# File 'lib/readme/filter.rb', line 23 def initialize(filter_fields) @allowed_fields = filter_fields end |
Instance Method Details
#filter(hash) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/readme/filter.rb', line 27 def filter(hash) allowed_fields = @allowed_fields.map(&:downcase) allowed_params, rejected_params = hash.partition { |key, _value| allowed_fields.include?(key.downcase) }.map(&:to_h) allowed_params.merge(Filter.redact(rejected_params)) end |
#pass_through? ⇒ Boolean
34 35 36 |
# File 'lib/readme/filter.rb', line 34 def pass_through? false end |