attr_redactor 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/attr_redactor.rb +7 -2
- data/lib/attr_redactor/version.rb +1 -1
- data/test/attr_redactor_test.rb +37 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f578d29ba5a97e39459babbeaf72368d01583755
|
4
|
+
data.tar.gz: e7948b03444ab69572868cac243496c3fc68392e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25f8e41a9b15875b1ef3bf912f859a226497c4251ce41084db1253d969c2fb10e840b2cb248bfc668310e58c01a94d2715c2dfd5fa3d653a73379e15626e6228
|
7
|
+
data.tar.gz: a7991c609324a0214da84a0d93997b9d6b417388ea1861ff27b02b87b812ab46182fd9d57cec465d7e3707a2e7fb1969b6883e6c85d6b7d89373c2996edd913e
|
data/CHANGELOG.md
CHANGED
data/lib/attr_redactor.rb
CHANGED
@@ -95,8 +95,13 @@ module AttrRedactor
|
|
95
95
|
attr_reader redacted_attribute_name unless instance_methods_as_symbols.include?(redacted_attribute_name)
|
96
96
|
attr_writer redacted_attribute_name unless instance_methods_as_symbols.include?(:"#{redacted_attribute_name}=")
|
97
97
|
|
98
|
+
hash_redactor_options = options.dup
|
99
|
+
|
100
|
+
# Don't pass the filter mode in, in case it's dynamic
|
101
|
+
hash_redactor_options.delete :filter_mode
|
102
|
+
|
98
103
|
# Create a redactor for the attribute
|
99
|
-
options[:redactor] = HashRedactor::HashRedactor.new(
|
104
|
+
options[:redactor] = HashRedactor::HashRedactor.new(hash_redactor_options)
|
100
105
|
|
101
106
|
define_method(attribute) do
|
102
107
|
instance_variable_get("@#{attribute}") || instance_variable_set("@#{attribute}", unredact(attribute, send(redacted_attribute_name)))
|
@@ -283,7 +288,7 @@ module AttrRedactor
|
|
283
288
|
def evaluated_attr_redacted_options_for(attribute)
|
284
289
|
evaluated_options = Hash.new
|
285
290
|
attribute_option_value = redacted_attributes[attribute.to_sym][:attribute]
|
286
|
-
redacted_attributes[attribute.to_sym].
|
291
|
+
redacted_attributes[attribute.to_sym].each do |option, value|
|
287
292
|
evaluated_options[option] = evaluate_attr_redactor_option(value)
|
288
293
|
end
|
289
294
|
|
data/test/attr_redactor_test.rb
CHANGED
@@ -73,6 +73,29 @@ class Post
|
|
73
73
|
attr_accessor :redact_hash
|
74
74
|
end
|
75
75
|
|
76
|
+
class DynamicPost
|
77
|
+
extend AttrRedactor
|
78
|
+
|
79
|
+
def self.encryption_key
|
80
|
+
'a completely different key, equally unguessable'
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.digest_salt
|
84
|
+
'saltier'
|
85
|
+
end
|
86
|
+
|
87
|
+
attr_redactor_options.merge! encryption_key: encryption_key,
|
88
|
+
digest_salt: digest_salt
|
89
|
+
|
90
|
+
attr_accessor :mode
|
91
|
+
|
92
|
+
attr_redactor :post_info, :redact => { email: 'keep' }, :filter_mode => :filter_mode
|
93
|
+
|
94
|
+
def filter_mode
|
95
|
+
mode
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
76
99
|
class SubClass < AlternativeClass
|
77
100
|
attr_redactor :testing
|
78
101
|
end
|
@@ -284,6 +307,20 @@ class AttrRedactorTest < Minitest::Test
|
|
284
307
|
assert_equal unredacted_data, @user.data
|
285
308
|
end
|
286
309
|
|
310
|
+
def test_whitelist_from_function
|
311
|
+
@post_whitelist = DynamicPost.new
|
312
|
+
@post_blacklist = DynamicPost.new
|
313
|
+
|
314
|
+
@post_whitelist.mode = :whitelist
|
315
|
+
@post_blacklist.mode = :blacklist
|
316
|
+
|
317
|
+
@post_whitelist.post_info = data_to_redact
|
318
|
+
@post_blacklist.post_info = data_to_redact
|
319
|
+
|
320
|
+
assert_equal @post_blacklist.post_info, data_to_redact
|
321
|
+
assert_equal @post_whitelist.post_info, { email: data_to_redact[:email] }
|
322
|
+
end
|
323
|
+
|
287
324
|
def test_redact_hash_from_function
|
288
325
|
post_data = { :followers => 'macy, george', :critics => 'Barbados Glum',
|
289
326
|
:bio => 'A strange, quiet man' }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_redactor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Jensen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hash_redactor
|