Class: ParamProtected::Protector

Inherits:
Object
  • Object
show all
Defined in:
lib/param_protected/protector.rb

Instance Method Summary collapse

Constructor Details

#initializeProtector

Returns a new instance of Protector.



3
4
5
# File 'lib/param_protected/protector.rb', line 3

def initialize
  @protections = []
end

Instance Method Details

#declare_protection(params, options, exclusivity) ⇒ Object



11
12
13
14
15
# File 'lib/param_protected/protector.rb', line 11

def declare_protection(params, options, exclusivity)
  params  = normalize_params(params)
  actions, condition = normalize_options(options)
  @protections << [params, actions, condition, exclusivity]
end

#initialize_copy(copy) ⇒ Object



7
8
9
# File 'lib/param_protected/protector.rb', line 7

def initialize_copy(copy)
  copy.instance_variable_set(:@protections, deep_copy(@protections))
end

#protect(controller, controller_params, action_name) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/param_protected/protector.rb', line 17

def protect(controller, controller_params, action_name)
  deep_copy(controller_params).tap do |params|
    protections_for_action(controller, action_name).each do |exclusivity, protected_params|
      filter_params(protected_params, params, exclusivity) unless protected_params.empty?
    end
  end
end