attr_masker 0.3.0 → 0.3.1
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/.github/workflows/tests.yml +31 -20
- data/Gemfile +2 -2
- data/README.adoc +20 -0
- data/gemfiles/Rails-6.1.gemfile +3 -0
- data/lib/attr_masker/error.rb +1 -0
- data/lib/attr_masker/maskers/replacing.rb +1 -0
- data/lib/attr_masker/maskers/simple.rb +3 -0
- data/lib/attr_masker/model.rb +3 -0
- data/lib/attr_masker/version.rb +1 -1
- data/lib/tasks/db.rake +3 -0
- data/spec/dummy/config/attr_masker.rb +1 -0
- data/spec/features/shared_examples.rb +4 -0
- data/spec/support/force_config_file_reload.rb +9 -0
- data/spec/unit/rake_task_spec.rb +16 -0
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ea11966d0da57a262387f54288c40df983b8f81756237ec3eb56e3907f49f4b
|
4
|
+
data.tar.gz: 15d5f3edbf6a072069d5107373e1cd0ccc78f9c554a8c2a5624620e4f6ce8b36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1c41e5e356c0660b720996f31eb2357a5559d10fe499ffe018462f593ca03c7f9afc853aa922bc70d4b9276c1e7d361273b052234f56287dd82ec7c878e71f3
|
7
|
+
data.tar.gz: 3d007123bf82fb0380aada1bd4d82df8295d5531dbac0a8742ae4650f37b6cc01bd4144e72fa928a3463c7601f6745d50d01d7b86b46c9c2506a185f6768a6a5
|
data/.github/workflows/tests.yml
CHANGED
@@ -3,6 +3,7 @@ name: Tests
|
|
3
3
|
on:
|
4
4
|
- pull_request
|
5
5
|
- push
|
6
|
+
- workflow_dispatch
|
6
7
|
|
7
8
|
jobs:
|
8
9
|
test:
|
@@ -19,11 +20,13 @@ jobs:
|
|
19
20
|
max-parallel: 10
|
20
21
|
matrix:
|
21
22
|
ruby:
|
22
|
-
-
|
23
|
-
- 2.
|
24
|
-
- 2.
|
25
|
-
- 2.
|
23
|
+
- "3.0"
|
24
|
+
- "2.7"
|
25
|
+
- "2.6"
|
26
|
+
- "2.5"
|
27
|
+
- "2.4"
|
26
28
|
gemfile:
|
29
|
+
- Rails-6.1
|
27
30
|
- Rails-6.0
|
28
31
|
- Rails-5.2
|
29
32
|
- Rails-5.1
|
@@ -34,25 +37,37 @@ jobs:
|
|
34
37
|
- activerecord
|
35
38
|
- mongoid
|
36
39
|
|
40
|
+
include:
|
41
|
+
# Rails 4.2 requires Bundler 1.x.
|
42
|
+
- gemfile: Rails-4.2
|
43
|
+
bundler_version: "1.17"
|
44
|
+
|
37
45
|
exclude:
|
38
|
-
# Rails 4.2 refuses to install on Ruby 2.7
|
39
|
-
|
46
|
+
# Rails 4.2 refuses to install on Ruby 2.7 and newer.
|
47
|
+
- gemfile: Rails-4.2
|
48
|
+
ruby: "3.0"
|
40
49
|
- gemfile: Rails-4.2
|
41
|
-
ruby: 2.7
|
42
|
-
# Rails
|
50
|
+
ruby: "2.7"
|
51
|
+
# Rails 5.x won't work with Ruby 3.0 and newer. See:
|
52
|
+
# - https://github.com/rails/rails/issues/40938#issuecomment-751569171
|
53
|
+
# - https://weblog.rubyonrails.org/2020/5/6/Rails-6-0-3-has-been-released/
|
54
|
+
- gemfile: Rails-5.2
|
55
|
+
ruby: "3.0"
|
56
|
+
- gemfile: Rails-5.1
|
57
|
+
ruby: "3.0"
|
58
|
+
- gemfile: Rails-5.0
|
59
|
+
ruby: "3.0"
|
60
|
+
# Rails 6 requires Ruby 2.5 or above
|
61
|
+
- gemfile: Rails-6.1
|
62
|
+
ruby: "2.4"
|
43
63
|
- gemfile: Rails-6.0
|
44
|
-
ruby: 2.4
|
64
|
+
ruby: "2.4"
|
45
65
|
|
46
66
|
env:
|
47
67
|
# For Bundler control variables, refer to:
|
48
68
|
# https://bundler.io/v1.17/bundle_config.html
|
49
69
|
BUNDLE_GEMFILE: ${{ format('gemfiles/{0}.gemfile', matrix.gemfile) }}
|
50
70
|
|
51
|
-
# Rails 4.2 requires Bundler 1.x.
|
52
|
-
# BUNDLE_ALLOW_BUNDLER_DEPENDENCY_CONFLICTS overrides that requirement.
|
53
|
-
# See: https://bundler.io/v2.1/man/bundle-config.1.html
|
54
|
-
BUNDLE_ALLOW_BUNDLER_DEPENDENCY_CONFLICTS: 1
|
55
|
-
|
56
71
|
steps:
|
57
72
|
- uses: actions/checkout@v2
|
58
73
|
|
@@ -67,12 +82,8 @@ jobs:
|
|
67
82
|
uses: ruby/setup-ruby@v1
|
68
83
|
with:
|
69
84
|
ruby-version: ${{ matrix.ruby }}
|
70
|
-
|
71
|
-
|
72
|
-
run: gem install bundler
|
73
|
-
|
74
|
-
- name: Install gems
|
75
|
-
run: bundle install --jobs 4 --retry 3
|
85
|
+
bundler: ${{ matrix.bundler_version || '2' }}
|
86
|
+
bundler-cache: true
|
76
87
|
|
77
88
|
- name: Run tests
|
78
89
|
run: bundle exec rspec
|
data/Gemfile
CHANGED
@@ -4,5 +4,5 @@ gemspec
|
|
4
4
|
|
5
5
|
gem "mongoid", require: false
|
6
6
|
|
7
|
-
gem "database_cleaner-active_record", require: false
|
8
|
-
gem "database_cleaner-mongoid", require: false
|
7
|
+
gem "database_cleaner-active_record", "~> 1.8", require: false
|
8
|
+
gem "database_cleaner-mongoid", "~> 1.8", require: false
|
data/README.adoc
CHANGED
@@ -163,6 +163,26 @@ This list is likely to be extended in future versions, and that will not be
|
|
163
163
|
considered a breaking change, therefore it is strongly recommended to always
|
164
164
|
use a splat (`**`) at end of argument list of masker's `#call` method.
|
165
165
|
|
166
|
+
=== Configuration file
|
167
|
+
|
168
|
+
It is also possible to contain all the maskers configuration in one file.
|
169
|
+
Just place it in `config/attr_masker.rb`, and it will be loaded from a Rake
|
170
|
+
task after the application is fully loaded. That means you can re-open classes
|
171
|
+
and add masker definitions there, for example:
|
172
|
+
|
173
|
+
[source,ruby]
|
174
|
+
----
|
175
|
+
# config/attr_masker.rb
|
176
|
+
|
177
|
+
class User
|
178
|
+
attr_masker :first_name, :last_name
|
179
|
+
end
|
180
|
+
|
181
|
+
class Email
|
182
|
+
attr_masker :address, ->(model:, **) { "mail#{model.id}@example.com" }
|
183
|
+
end
|
184
|
+
----
|
185
|
+
|
166
186
|
== Roadmap & TODOs
|
167
187
|
|
168
188
|
- documentation
|
data/lib/attr_masker/error.rb
CHANGED
data/lib/attr_masker/model.rb
CHANGED
data/lib/attr_masker/version.rb
CHANGED
data/lib/tasks/db.rake
CHANGED
@@ -15,6 +15,9 @@ namespace :db do
|
|
15
15
|
task :mask => :environment do
|
16
16
|
Rails.application.eager_load!
|
17
17
|
|
18
|
+
config_file = Rails.root.join("config", "attr_masker.rb").to_s
|
19
|
+
require config_file if File.file?(config_file)
|
20
|
+
|
18
21
|
performers = AttrMasker::Performer::Base.descendants.map(&:new)
|
19
22
|
performers.select!(&:dependencies_available?)
|
20
23
|
|
@@ -0,0 +1 @@
|
|
1
|
+
$CONFIG_LOADED_AT = Time.now
|
@@ -370,6 +370,10 @@ RSpec.shared_examples "Attr Masker gem feature specs" do
|
|
370
370
|
end
|
371
371
|
end
|
372
372
|
|
373
|
+
example "It loads configuration file", :force_config_file_reload do
|
374
|
+
expect { run_rake_task }.to change { $CONFIG_LOADED_AT }
|
375
|
+
end
|
376
|
+
|
373
377
|
def run_rake_task
|
374
378
|
Rake::Task["db:mask"].execute
|
375
379
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
RSpec.configure do |config|
|
2
|
+
config.before(:each, :force_config_file_reload) do
|
3
|
+
config_path = Rails.root.join("config", "attr_masker.rb").to_s
|
4
|
+
# $" holds names of source files which have been loaded already.
|
5
|
+
# Removing a path from that list causes given file to be loaded
|
6
|
+
# again at next #require call.
|
7
|
+
$".delete(config_path)
|
8
|
+
end
|
9
|
+
end
|
data/spec/unit/rake_task_spec.rb
CHANGED
@@ -6,9 +6,25 @@ require "spec_helper"
|
|
6
6
|
RSpec.describe "db:mask", :suppress_progressbar do
|
7
7
|
subject { Rake::Task["db:mask"] }
|
8
8
|
|
9
|
+
let(:config_file_path) do
|
10
|
+
File.expand_path("../dummy/config/attr_masker.rb", __dir__)
|
11
|
+
end
|
12
|
+
|
9
13
|
it "loads all application's models eagerly" do
|
10
14
|
expect(Rails.application).to receive(:eager_load!)
|
11
15
|
subject.execute
|
12
16
|
expect(defined? NonPersistedModel).to be_truthy
|
13
17
|
end
|
18
|
+
|
19
|
+
it "loads configuration file if it exists", :force_config_file_reload do
|
20
|
+
allow(File).to receive(:file?).and_call_original
|
21
|
+
allow(File).to receive(:file?).with(config_file_path).and_return(true)
|
22
|
+
expect { subject.execute }.to change { $CONFIG_LOADED_AT }
|
23
|
+
end
|
24
|
+
|
25
|
+
it "works without configuration file", :force_config_file_reload do
|
26
|
+
allow(File).to receive(:file?).and_call_original
|
27
|
+
allow(File).to receive(:file?).with(config_file_path).and_return(false)
|
28
|
+
expect { subject.execute }.not_to change { $CONFIG_LOADED_AT }
|
29
|
+
end
|
14
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_masker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -249,6 +249,7 @@ files:
|
|
249
249
|
- gemfiles/Rails-5.1.gemfile
|
250
250
|
- gemfiles/Rails-5.2.gemfile
|
251
251
|
- gemfiles/Rails-6.0.gemfile
|
252
|
+
- gemfiles/Rails-6.1.gemfile
|
252
253
|
- gemfiles/Rails-head.gemfile
|
253
254
|
- gemfiles/common.gemfile
|
254
255
|
- lib/attr_masker.rb
|
@@ -262,6 +263,7 @@ files:
|
|
262
263
|
- lib/attr_masker/version.rb
|
263
264
|
- lib/tasks/db.rake
|
264
265
|
- spec/dummy/app/models/non_persisted_model.rb
|
266
|
+
- spec/dummy/config/attr_masker.rb
|
265
267
|
- spec/dummy/config/database.yml
|
266
268
|
- spec/dummy/config/mongoid.yml
|
267
269
|
- spec/dummy/config/routes.rb
|
@@ -275,6 +277,7 @@ files:
|
|
275
277
|
- spec/support/10_mongoid_env.rb
|
276
278
|
- spec/support/20_combustion.rb
|
277
279
|
- spec/support/db_cleaner.rb
|
280
|
+
- spec/support/force_config_file_reload.rb
|
278
281
|
- spec/support/matchers.rb
|
279
282
|
- spec/support/rake.rb
|
280
283
|
- spec/support/silence_stdout.rb
|
@@ -287,7 +290,7 @@ homepage: https://github.com/riboseinc/attr_masker
|
|
287
290
|
licenses:
|
288
291
|
- MIT
|
289
292
|
metadata: {}
|
290
|
-
post_install_message:
|
293
|
+
post_install_message:
|
291
294
|
rdoc_options: []
|
292
295
|
require_paths:
|
293
296
|
- lib
|
@@ -302,12 +305,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
302
305
|
- !ruby/object:Gem::Version
|
303
306
|
version: '0'
|
304
307
|
requirements: []
|
305
|
-
rubygems_version: 3.
|
306
|
-
signing_key:
|
308
|
+
rubygems_version: 3.2.3
|
309
|
+
signing_key:
|
307
310
|
specification_version: 4
|
308
311
|
summary: Masking attributes
|
309
312
|
test_files:
|
310
313
|
- spec/dummy/app/models/non_persisted_model.rb
|
314
|
+
- spec/dummy/config/attr_masker.rb
|
311
315
|
- spec/dummy/config/database.yml
|
312
316
|
- spec/dummy/config/mongoid.yml
|
313
317
|
- spec/dummy/config/routes.rb
|
@@ -321,6 +325,7 @@ test_files:
|
|
321
325
|
- spec/support/10_mongoid_env.rb
|
322
326
|
- spec/support/20_combustion.rb
|
323
327
|
- spec/support/db_cleaner.rb
|
328
|
+
- spec/support/force_config_file_reload.rb
|
324
329
|
- spec/support/matchers.rb
|
325
330
|
- spec/support/rake.rb
|
326
331
|
- spec/support/silence_stdout.rb
|