secret_string 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adc3ac2c2e93e1c310c878c4194525a165c390dccd2d6708186f54bb1147be9a
4
- data.tar.gz: d7be0b22cd44ec755337957965a140bb155c811f6223cf5264217ab591e17976
3
+ metadata.gz: 5f912f9e56675854f647fb6a965c6e3cfac83e999827249cdac00bbe096c3fc8
4
+ data.tar.gz: dc352220e6220adc7555be9064855990f6171938621634db7eca177bf6ede15f
5
5
  SHA512:
6
- metadata.gz: 5b4daa15f269466054ac21521c1d5cf4f7912bcdf7d811807046a2c3f69cbca3f398381a0a9d0d205bb8778a2f59cab0ca7bbb518ece5dca243c6d358d298c90
7
- data.tar.gz: d922cfba5e22b7098f7ca19501f364a8d912ef17da44d409152d79e7ad0d901a19031bdabd4fc1a2472703f5e4696510b10a4cc47863360eff1fa16547f94ace
6
+ metadata.gz: 18344af3842f3a6e1198bb29b85165ac8dd72a5b9de990a6c4d690882792b63b8cd29c2440293bbdefc7b3b1980334b0fba3da053f302d708ee1348451a9d4f7
7
+ data.tar.gz: 20a5236e50e545c04df1e8de38187c92386dde543b76888681d3209fe9a05e46aa2dc38faa24b806523c034e899e250ecac9a7f351c91339f693001393b69f5c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # [v1.1.0](https://github.com/Muriel-Salvan/secret_string/compare/v1.0.1...v1.1.0) (2021-07-07 10:21:42)
2
+
3
+ ### Features
4
+
5
+ * [[Feature] Add equality and pattern matching facilities between String and SecretString](https://github.com/Muriel-Salvan/secret_string/commit/8bc056e66b21ee2d289e0c14fce43be9a0104434)
6
+
1
7
  # [v1.0.1](https://github.com/Muriel-Salvan/secret_string/compare/v1.0.0...v1.0.1) (2021-06-30 10:46:43)
2
8
 
3
9
  ### Patches
data/lib/secret_string.rb CHANGED
@@ -46,13 +46,22 @@ class SecretString
46
46
  @silenced_str = silenced_str
47
47
  end
48
48
 
49
- # Delegate the String representations methods to the silenced String by default
50
49
  extend Forwardable
50
+
51
+ # Delegate the String representations methods to the silenced String
51
52
  def_delegators :@silenced_str, *%i[
52
53
  inspect
53
54
  to_s
54
55
  ]
55
56
 
57
+ # Delegate the String identity methods to the unprotected String
58
+ def_delegators :@str, *%i[
59
+ ==
60
+ =~
61
+ match
62
+ size
63
+ ]
64
+
56
65
  # Return the unprotected String
57
66
  #
58
67
  # Result::
@@ -19,10 +19,24 @@ class SecretString
19
19
  # Nothing to do
20
20
  end
21
21
 
22
+ # Compare the String with another object
23
+ #
24
+ # Parameters::
25
+ # * *other* (Object): Other object
26
+ # Result::
27
+ # * Boolean: Are objects equal?
28
+ def ==(other)
29
+ if other.is_a?(SecretString)
30
+ other == self
31
+ else
32
+ super
33
+ end
34
+ end
35
+
22
36
  end
23
37
 
24
38
  end
25
39
 
26
40
  end
27
41
 
28
- String.include SecretString::CoreExtensions::String
42
+ String.prepend SecretString::CoreExtensions::String
@@ -1,5 +1,5 @@
1
1
  class SecretString
2
2
 
3
- VERSION = '1.0.1'
3
+ VERSION = '1.1.0'
4
4
 
5
5
  end
@@ -21,6 +21,22 @@ describe SecretString do
21
21
  expect(secret.to_unprotected).not_to eq 'MySecret'
22
22
  end
23
23
 
24
+ it 'equals correctly with a string having the same content' do
25
+ expect(secret).to eq 'MySecret'
26
+ end
27
+
28
+ it 'matches correctly with a string having the same content' do
29
+ expect(secret).to match(/Secret/)
30
+ end
31
+
32
+ it 'matches correctly using the =~ operator with a string having the same content' do
33
+ expect(secret =~ /Secret/).not_to be nil
34
+ end
35
+
36
+ it 'reports the correct size' do
37
+ expect(secret.size).to eq 'MySecret'.size
38
+ end
39
+
24
40
  end
25
41
 
26
42
  describe 'erase' do
@@ -10,4 +10,9 @@ describe String do
10
10
  expect(str).to eq 'MySecret'
11
11
  end
12
12
 
13
+ it 'equals the unprotected value of a secret string' do
14
+ str = 'MySecret'
15
+ expect(str).to eq SecretString.new('MySecret', silenced_str: 'SilencedString')
16
+ end
17
+
13
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secret_string
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Muriel Salvan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-30 00:00:00.000000000 Z
11
+ date: 2021-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec