Class: PackageProtections::ProtectedPackage

Inherits:
T::Struct
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/package_protections/protected_package.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from(original_package) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/package_protections/protected_package.rb', line 14

def self.from(original_package)
   = original_package.['protections'] || {}
  valid_identifiers = PackageProtections.all.map(&:identifier)
  protections = {}
  .each_key do |protection_key|
    protection = PackageProtections.with_identifier(protection_key)
    if !protection
      raise IncorrectPublicApiUsageError.new("Invalid configuration for package `#{original_package.name}`. The metadata key #{protection_key} is not a valid behaviors under the `protection` metadata namespace. Valid keys are #{valid_identifiers.inspect}. See https://github.com/rubyatscale/package_protections#readme for more info") # rubocop:disable Style/RaiseArgs
    end

    protections[protection.identifier] = get_violation_behavior(protection, , original_package)
  end

  unspecified_protections = valid_identifiers - protections.keys
  unspecified_protections.each do |protection_key|
    protections[protection_key] = PackageProtections.with_identifier(protection_key).default_behavior
  end

  new(
    original_package: original_package,
    protections: protections,
    deprecated_references: ParsePackwerk::DeprecatedReferences.for(original_package)
  )
end

.get_violation_behavior(protection, metadata, package) ⇒ Object



40
41
42
# File 'lib/package_protections/protected_package.rb', line 40

def self.get_violation_behavior(protection, , package)
  ViolationBehavior.from_raw_value([protection.identifier])
end

Instance Method Details

#dependenciesObject



65
66
67
# File 'lib/package_protections/protected_package.rb', line 65

def dependencies
  original_package.dependencies
end

#metadataObject



55
56
57
# File 'lib/package_protections/protected_package.rb', line 55

def 
  original_package.
end

#nameObject



50
51
52
# File 'lib/package_protections/protected_package.rb', line 50

def name
  original_package.name
end

#violation_behavior_for(key) ⇒ Object



45
46
47
# File 'lib/package_protections/protected_package.rb', line 45

def violation_behavior_for(key)
  protections.fetch(key)
end

#violationsObject



70
71
72
# File 'lib/package_protections/protected_package.rb', line 70

def violations
  deprecated_references.violations
end

#ymlObject



60
61
62
# File 'lib/package_protections/protected_package.rb', line 60

def yml
  original_package.yml
end