cloaked 0.1.0 → 0.2.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/.byebug_history +10 -0
- data/.rubocop.yml +1 -1
- data/Gemfile +0 -1
- data/README.md +1 -1
- data/lib/cloaked.rb +35 -27
- data/lib/cloaked/version.rb +1 -1
- metadata +3 -3
- data/rubocop.yml +0 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34b92448866e9dedb8c4d44ce12e87a9d7a30daecdeee57127615f5d3640aac6
|
4
|
+
data.tar.gz: 7a1f1a17bdeb80739812fe577320a3cc04c2d15a49e282db90c8a03b060cea57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01ccda96f597cccdd01075b4a3fb90e4f61248dfd949c2d1ea3e0a58ae91c5ffb044238f35209d74008b16b0866335f111f89a46ef4cf3f76b057626d2f4bc9e
|
7
|
+
data.tar.gz: 420a8a2e579d620da931c8d3859e5d42c3e61a5fbf8f758ba8bd6a22301105e414336d2def4dbe770df7370440d95ca63f012dc62f1522193c9e80b825ce76ed
|
data/.byebug_history
ADDED
data/.rubocop.yml
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require:
|
2
|
-
- rubocop-performance
|
3
2
|
- rubocop-rspec
|
4
3
|
|
5
4
|
# Max line length is changed from default 80
|
@@ -21,6 +20,7 @@ Metrics/BlockLength:
|
|
21
20
|
Exclude:
|
22
21
|
- 'Rakefile'
|
23
22
|
- '**/*.gemspec'
|
23
|
+
- 'spec/*.rb'
|
24
24
|
|
25
25
|
# Class top level documentation
|
26
26
|
Style/Documentation:
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -78,7 +78,7 @@ Only applies to `:base64` and `hex`. Note that in the latter case, the length of
|
|
78
78
|
|
79
79
|
## Contributing
|
80
80
|
|
81
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lightthefuserun/cloaked. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
82
82
|
|
83
83
|
## License
|
84
84
|
|
data/lib/cloaked.rb
CHANGED
@@ -17,46 +17,54 @@ module Cloaked
|
|
17
17
|
cattr_accessor :cloaked_fields, instance_reader: false
|
18
18
|
|
19
19
|
before_validation :cloak_fields
|
20
|
+
|
21
|
+
extend ClassMethods
|
22
|
+
include InstanceMethods
|
20
23
|
end
|
21
24
|
|
22
|
-
|
23
|
-
def with_cloaked_keys(
|
25
|
+
module ClassMethods
|
26
|
+
def with_cloaked_keys(*fields, size: DEFAULT_SIZE, prefix: '', method: :url_safe)
|
24
27
|
self.cloaked_fields ||= []
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
|
29
|
+
fields.each do |field|
|
30
|
+
self.cloaked_fields << {
|
31
|
+
field_name: field,
|
32
|
+
size: size,
|
33
|
+
prefix: prefix,
|
34
|
+
method: method
|
35
|
+
}
|
36
|
+
end
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
34
|
-
|
35
|
-
|
40
|
+
module InstanceMethods
|
41
|
+
def cloak_fields(force: false)
|
42
|
+
self.class.cloaked_fields ||= []
|
36
43
|
|
37
|
-
|
38
|
-
|
39
|
-
|
44
|
+
self.class.cloaked_fields.each do |field|
|
45
|
+
cloak_field(field.merge(force: force))
|
46
|
+
end
|
40
47
|
|
41
|
-
|
42
|
-
|
48
|
+
self
|
49
|
+
end
|
43
50
|
|
44
|
-
|
45
|
-
|
51
|
+
def cloak_field(field_name: nil, size: DEFAULT_SIZE, prefix: '', force: false, method: :url_safe)
|
52
|
+
return send(field_name) if send(field_name).present? && !force
|
46
53
|
|
47
|
-
|
54
|
+
cloaked_value = prefix.to_s + value(method, size)
|
48
55
|
|
49
|
-
|
50
|
-
|
56
|
+
return send("#{field_name}=", cloaked_value) unless self.class.exists?(field_name)
|
57
|
+
end
|
51
58
|
|
52
|
-
|
59
|
+
private
|
53
60
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
61
|
+
def value(method, size)
|
62
|
+
case method
|
63
|
+
when :uuid then SecureRandom.uuid
|
64
|
+
when :hex then SecureRandom.hex(size)
|
65
|
+
when :url_safe then SecureRandom.urlsafe_base64(size)
|
66
|
+
else raise InvalidMethod
|
67
|
+
end
|
60
68
|
end
|
61
69
|
end
|
62
70
|
end
|
data/lib/cloaked/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloaked
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rui Freitas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -101,6 +101,7 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
+
- ".byebug_history"
|
104
105
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
105
106
|
- ".gitignore"
|
106
107
|
- ".rspec"
|
@@ -119,7 +120,6 @@ files:
|
|
119
120
|
- lib/cloaked/active_record/cloaked/active_record.rb
|
120
121
|
- lib/cloaked/railtie.rb
|
121
122
|
- lib/cloaked/version.rb
|
122
|
-
- rubocop.yml
|
123
123
|
homepage: https://github.com/lightthefuserun/cloaked
|
124
124
|
licenses:
|
125
125
|
- MIT
|
data/rubocop.yml
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
---
|
2
|
-
require:
|
3
|
-
- rubocop-performance
|
4
|
-
- rubocop-rspec
|
5
|
-
|
6
|
-
AllCops:
|
7
|
-
TargetRubyVersion: 2.6.5
|
8
|
-
Include:
|
9
|
-
- lib/**/*.rb
|
10
|
-
- spec/**/*.rb
|
11
|
-
Exclude:
|
12
|
-
- bin/**/*
|
13
|
-
- exe/**/*
|
14
|
-
- benchmark/**/*
|
15
|
-
- script/**/*
|
16
|
-
- vendor/**/*
|
17
|
-
- tmp/**/*
|
18
|
-
Layout/IndentationWidth:
|
19
|
-
Severity: error
|
20
|
-
Layout/FirstArrayElementIndentation:
|
21
|
-
EnforcedStyle: consistent
|
22
|
-
Layout/FirstHashElementIndentation:
|
23
|
-
EnforcedStyle: consistent
|
24
|
-
Layout/MultilineMethodCallIndentation:
|
25
|
-
EnforcedStyle: indented
|
26
|
-
Layout/MultilineOperationIndentation:
|
27
|
-
EnforcedStyle: indented
|
28
|
-
Layout/EmptyComment:
|
29
|
-
Enabled: false
|
30
|
-
Layout/EndAlignment:
|
31
|
-
Severity: error
|
32
|
-
Lint/UnreachableCode:
|
33
|
-
Severity: error
|
34
|
-
Metrics/AbcSize:
|
35
|
-
Max: 21
|
36
|
-
Metrics/BlockLength:
|
37
|
-
Exclude:
|
38
|
-
- spec/**/*.rb
|
39
|
-
- rake/*.rake
|
40
|
-
Metrics/ClassLength:
|
41
|
-
Exclude:
|
42
|
-
- !ruby/regexp /features\/.*.rb$/
|
43
|
-
- !ruby/regexp /spec\/.*.rb$/
|
44
|
-
Max: 240
|
45
|
-
Metrics/CyclomaticComplexity:
|
46
|
-
Exclude:
|
47
|
-
- lib/jekyll/utils.rb
|
48
|
-
- lib/jekyll/commands/serve.rb
|
49
|
-
Metrics/LineLength:
|
50
|
-
Exclude:
|
51
|
-
- !ruby/regexp /features\/.*.rb/
|
52
|
-
- Rakefile
|
53
|
-
- rake/*.rake
|
54
|
-
- Gemfile
|
55
|
-
Max: 120
|
56
|
-
Severity: warning
|
57
|
-
Metrics/MethodLength:
|
58
|
-
CountComments: false
|
59
|
-
Max: 20
|
60
|
-
Severity: error
|
61
|
-
Metrics/ModuleLength:
|
62
|
-
Max: 240
|
63
|
-
Metrics/ParameterLists:
|
64
|
-
Max: 4
|
65
|
-
Metrics/PerceivedComplexity:
|
66
|
-
Max: 8
|
67
|
-
Naming/FileName:
|
68
|
-
Enabled: false
|
69
|
-
Naming/HeredocDelimiterNaming:
|
70
|
-
Exclude:
|
71
|
-
- spec/**/*.rb
|
72
|
-
Security/MarshalLoad:
|
73
|
-
Exclude:
|
74
|
-
- !ruby/regexp /spec\/.*.rb$/
|
75
|
-
Security/YAMLLoad:
|
76
|
-
Exclude:
|
77
|
-
- !ruby/regexp /features\/.*.rb/
|
78
|
-
- !ruby/regexp /spec\/.*.rb$/
|
79
|
-
Style/AccessModifierDeclarations:
|
80
|
-
Enabled: false
|
81
|
-
Style/Alias:
|
82
|
-
EnforcedStyle: prefer_alias_method
|
83
|
-
Style/AndOr:
|
84
|
-
Severity: error
|
85
|
-
Style/ClassAndModuleChildren:
|
86
|
-
Exclude:
|
87
|
-
- spec/**/*.rb
|
88
|
-
Style/FrozenStringLiteralComment:
|
89
|
-
EnforcedStyle: always
|
90
|
-
Style/Documentation:
|
91
|
-
Enabled: false
|
92
|
-
Style/DoubleNegation:
|
93
|
-
Enabled: false
|
94
|
-
Style/GuardClause:
|
95
|
-
Enabled: false
|
96
|
-
Style/HashSyntax:
|
97
|
-
EnforcedStyle: ruby19
|
98
|
-
Severity: error
|
99
|
-
Style/ModuleFunction:
|
100
|
-
Enabled: false
|
101
|
-
Style/MultilineTernaryOperator:
|
102
|
-
Severity: error
|