package_protections 0.64.0 → 0.67.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: f1b60522d3be3ff25aaab73a4c0e6d4d0585657663352b9c353d6df3307287c4
4
- data.tar.gz: 8b57faaea71bfb8b64f842b7e2ec40cdc313bc2c674243a698c9dc7bcbc21b56
3
+ metadata.gz: '0457664569f574f7252c13cd8236b6e267a114bd900a24da1aa4a89c4b5d13da'
4
+ data.tar.gz: 8495e9bc7343afa5c793ef7027c2e453dbe13424de49514e235dcd3f64327031
5
5
  SHA512:
6
- metadata.gz: e35ac2ae85c9459f3e480ba9939bf7e5db0902049c3643620e3ba2478a443c87dfe1ac1c9029254d7f616ac0d4821df3d07625e332a431349ff4860d5f46e64e
7
- data.tar.gz: c90972ea3fbf86c36ea1492948fa56cd42e2b38731f6e9410c69296286d43310e7104413ccb20206392e1546e3b82c23ea25ba16defe09960718b7dadb63189f
6
+ metadata.gz: 04cfbf3ce493c4dbb3a9ddfbeb89d725a1fbcc7d5d209e1a51e45ecee6fb56320dacb9fb271d3ca58d1b5d176b209a6410630de041d7e4f749368f7820443ed4
7
+ data.tar.gz: 67412edbc0ac4a0c64460419c482a141963120c89bb46c297bb84575c83b9f38920bfa7cee9549a7f8c135275eca0927127fa89c5f1879480d283201e757b60f
data/README.md CHANGED
@@ -128,6 +128,18 @@ PackageProtections.set_defaults!(packages)
128
128
  PackageProtections.set_defaults!(packages.select{|p| p.package_name == 'packs/my_package'})
129
129
  ```
130
130
 
131
+ ## Custom Protections
132
+
133
+ It's possible to create your own custom protections that go through this interface. To do this, you just need to implement a protection and configure `PackageProtections`.
134
+
135
+ ```ruby
136
+ PackageProtections.configure do |config|
137
+ config.protections += [MyCustomProtection]
138
+ end
139
+ ```
140
+
141
+ In this example, `MyCustomProtection` needs to implement the `PackageProtections::ProtectionInterface` (for protections powered by `packwerk` that look at new and existing violations) OR `PackageProtections::RubocopProtectionInterface` (for protections powered by `rubocop` that look at the AST). It's recommended to take a look at the existing protections as examples. If you're having any trouble with this, please file an issue and we'll be glad to help.
142
+
131
143
  ## Incorporating into your CI Pipeline
132
144
  Your CI pipeline can execute the public API ta and fail if there are any offenses.
133
145
 
@@ -0,0 +1,38 @@
1
+ # typed: strict
2
+
3
+ module PackageProtections
4
+ module Private
5
+ class Configuration
6
+ extend T::Sig
7
+
8
+ sig { params(protections: T::Array[ProtectionInterface]).void }
9
+ attr_writer :protections
10
+
11
+ sig { void }
12
+ def initialize
13
+ @protections = T.let(default_protections, T::Array[ProtectionInterface])
14
+ end
15
+
16
+ sig { returns(T::Array[ProtectionInterface]) }
17
+ def protections
18
+ @protections
19
+ end
20
+
21
+ sig { void }
22
+ def bust_cache!
23
+ @protections = default_protections
24
+ end
25
+
26
+ sig { returns(T::Array[ProtectionInterface]) }
27
+ def default_protections
28
+ [
29
+ Private::OutgoingDependencyProtection.new,
30
+ Private::IncomingPrivacyProtection.new,
31
+ Private::TypedApiProtection.new,
32
+ Private::MultipleNamespacesProtection.new,
33
+ Private::VisibilityProtection.new
34
+ ]
35
+ end
36
+ end
37
+ end
38
+ end
@@ -9,6 +9,7 @@ require 'package_protections/private/outgoing_dependency_protection'
9
9
  require 'package_protections/private/metadata_modifiers'
10
10
  require 'package_protections/private/multiple_namespaces_protection'
11
11
  require 'package_protections/private/visibility_protection'
12
+ require 'package_protections/private/configuration'
12
13
 
13
14
  module PackageProtections
14
15
  #
@@ -18,6 +19,12 @@ module PackageProtections
18
19
  module Private
19
20
  extend T::Sig
20
21
 
22
+ sig { returns(Private::Configuration) }
23
+ def self.config
24
+ @config = T.let(@config, T.nilable(Configuration))
25
+ @config ||= Private::Configuration.new
26
+ end
27
+
21
28
  sig do
22
29
  params(
23
30
  packages: T::Array[ParsePackwerk::Package],
@@ -138,6 +145,7 @@ module PackageProtections
138
145
  def self.bust_cache!
139
146
  @protected_packages_indexed_by_name = nil
140
147
  @private_cop_config = nil
148
+ config.bust_cache!
141
149
  end
142
150
 
143
151
  sig { params(identifier: Identifier).returns(T::Hash[T.untyped, T.untyped]) }
@@ -38,20 +38,18 @@ module PackageProtections
38
38
  # Implementation of rubocop-based protections
39
39
  require 'rubocop/cop/package_protections/namespaced_under_package_name'
40
40
 
41
- #
42
- # These are all of the concrete implementations of the `ProtectionInterface`.
43
- # This list is added to when a new protection is created, but in the future,
44
- # this list may be injected by the client.
45
- #
41
+ class << self
42
+ extend T::Sig
43
+
44
+ sig { params(blk: T.proc.params(arg0: Private::Configuration).void).void }
45
+ def configure(&blk)
46
+ yield(Private.config)
47
+ end
48
+ end
49
+
46
50
  sig { returns(T::Array[ProtectionInterface]) }
47
51
  def self.all
48
- [
49
- Private::OutgoingDependencyProtection.new,
50
- Private::IncomingPrivacyProtection.new,
51
- Private::TypedApiProtection.new,
52
- Private::MultipleNamespacesProtection.new,
53
- Private::VisibilityProtection.new
54
- ]
52
+ Private.config.protections
55
53
  end
56
54
 
57
55
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: package_protections
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.64.0
4
+ version: 0.67.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-04 00:00:00.000000000 Z
11
+ date: 2022-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -178,6 +178,7 @@ files:
178
178
  - lib/package_protections/per_file_violation.rb
179
179
  - lib/package_protections/private.rb
180
180
  - lib/package_protections/private/colorized_string.rb
181
+ - lib/package_protections/private/configuration.rb
181
182
  - lib/package_protections/private/incoming_privacy_protection.rb
182
183
  - lib/package_protections/private/metadata_modifiers.rb
183
184
  - lib/package_protections/private/multiple_namespaces_protection.rb