blob: da8f9892f9cdfb4a947abdb06865663d01bacd6a (
plain) (
blame)
1
2
3
4
5
6
7
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
36
37
38
39
40
|
# frozen_string_literal: true
require "active_support/core_ext/hash/indifferent_access"
class ProtectedParams
delegate :keys, :key?, :has_key?, :empty?, to: :@parameters
def initialize(parameters = {})
@parameters = parameters.with_indifferent_access
@permitted = false
end
def permitted?
@permitted
end
def permit!
@permitted = true
self
end
def [](key)
@parameters[key]
end
def to_h
@parameters.to_h
end
alias to_unsafe_h to_h
def stringify_keys
dup
end
def dup
super.tap do |duplicate|
duplicate.instance_variable_set :@permitted, @permitted
end
end
end
|