Module: ModerateParameters::Parameters

Included in:
ActionController::Parameters
Defined in:
lib/moderate_parameters/parameters.rb

Constant Summary collapse

MP_OBJECT_ID =
:@moderate_params_object_id
MP_PARENT_KEY =
:@moderate_params_parent_key

Instance Method Summary collapse

Instance Method Details

#moderate(controller_name, action, *filters) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/moderate_parameters/parameters.rb', line 8

def moderate(controller_name, action, *filters)
  log_duplicate_moderate_warning(
    caller_locations,
    instance_variable_get(MP_PARENT_KEY),
    controller_name,
    action
  ) if instance_variable_get(MP_OBJECT_ID)

  params = self.class.new

  filters.each do |filter|
    case filter
    when Symbol, String
      if non_scalar?(self[filter])
        non_scalar_value_filter(params, filter, controller_name, action)
      else
        permitted_scalar_filter(params, filter)
      end
    when Hash
      cust_hash_filter(params, filter, controller_name, action)
    end
  end

  incoming_params_logging(params, controller_name, action)
  duplicate_params = dup
  instance_variable_set(MP_OBJECT_ID, duplicate_params.object_id)
  duplicate_params.permit!
end

#require(key) ⇒ Object



37
38
39
40
41
# File 'lib/moderate_parameters/parameters.rb', line 37

def require(key)
  return super if key.is_a?(Array) || self[key].blank?
  self[key].instance_variable_set(MP_PARENT_KEY, key)
  super
end