Class: ParamProtected::Protector

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProtector



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

def initialize
  @protections = []
end

Class Method Details

.instance(controller) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/param_protected/protector.rb', line 4

def self.instance(controller)
  unless controller.respond_to?(:pp_protector)
    controller.class_eval{ @pp_protector = Protector.new }
    controller.singleton_class.class_eval { attr_reader :pp_protector }
  end
  controller.pp_protector
end

Instance Method Details

#declare_protection(params, options, exclusivity) ⇒ Object



20
21
22
23
24
# File 'lib/param_protected/protector.rb', line 20

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



16
17
18
# File 'lib/param_protected/protector.rb', line 16

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

#protect(controller, controller_params, action_name) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/param_protected/protector.rb', line 26

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