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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8f5402fd6e0a62adeed50b6326b8c5a890cfee8
4
- data.tar.gz: e2023832b6878e36199642220921e6270107e056
3
+ metadata.gz: f578d29ba5a97e39459babbeaf72368d01583755
4
+ data.tar.gz: e7948b03444ab69572868cac243496c3fc68392e
5
5
  SHA512:
6
- metadata.gz: a48ee64c229713ef201046b9d50ee1b2e6e7caa0508acfb1a37810dd230423758d6b5c5751d956a183d90bef70e8c74ee8295817df9fe8cfcbe52fd7fbb6f367
7
- data.tar.gz: b4e5f13e0925b34f1a4dfef7a32b0eee28eebdefa6771efcacb41a8233e858d4ede3143c799555677479be0d67fcf60bdfff98c94631405e9934e2b77a0663ba
6
+ metadata.gz: 25f8e41a9b15875b1ef3bf912f859a226497c4251ce41084db1253d969c2fb10e840b2cb248bfc668310e58c01a94d2715c2dfd5fa3d653a73379e15626e6228
7
+ data.tar.gz: a7991c609324a0214da84a0d93997b9d6b417388ea1861ff27b02b87b812ab46182fd9d57cec465d7e3707a2e7fb1969b6883e6c85d6b7d89373c2996edd913e
@@ -1,5 +1,8 @@
1
1
  # attr_redactor #
2
2
 
3
+ ##0.4.0 ##
4
+ * Added: Allow dynamic filter_mode on a per instance basis (@chrisjensen)
5
+
3
6
  ##0.3.0 ##
4
7
  * Changed: Version bump hash_redactor for string values for redact (@chrisjensen)
5
8
 
@@ -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(options)
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].map do |option, value|
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
 
@@ -2,7 +2,7 @@ module AttrRedactor
2
2
  # Contains information about this gem's version
3
3
  module Version
4
4
  MAJOR = 0
5
- MINOR = 3
5
+ MINOR = 4
6
6
  PATCH = 0
7
7
 
8
8
  # Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
@@ -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.3.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-08-23 00:00:00.000000000 Z
11
+ date: 2016-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hash_redactor