Class: Jets::Controller::ParametersFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/controller/parameters_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#filtersObject (readonly)

Returns the value of attribute filters.



5
6
7
# File 'lib/jets/controller/parameters_filter.rb', line 5

def filters
  @filters
end

#params_filterObject (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