Class: QueryPackwerk::Package

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/query_packwerk/package.rb

Overview

Represents a Packwerk package with enhanced querying capabilities. Wraps around ParsePackwerk::Package to provide additional methods for accessing package properties, dependencies, violations, and consumer information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_package:) ⇒ Package

Returns a new instance of Package.



15
16
17
# File 'lib/query_packwerk/package.rb', line 15

def initialize(original_package:)
  @original_package = original_package
end

Instance Attribute Details

#original_packageObject (readonly)

Returns the value of attribute original_package.



12
13
14
# File 'lib/query_packwerk/package.rb', line 12

def original_package
  @original_package
end

Instance Method Details

#configObject



40
41
42
# File 'lib/query_packwerk/package.rb', line 40

def config
  @original_package.config
end

#consumer_countsObject



96
97
98
# File 'lib/query_packwerk/package.rb', line 96

def consumer_counts
  violations.consumers
end

#consumer_namesObject



90
91
92
# File 'lib/query_packwerk/package.rb', line 90

def consumer_names
  violations.consumers.keys
end

#consumersObject



84
85
86
# File 'lib/query_packwerk/package.rb', line 84

def consumers
  Packages.where(name: consumer_names)
end

#deconstruct_keys(keys) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/query_packwerk/package.rb', line 110

def deconstruct_keys(keys)
  all_values = {
    name: name,
    owner: owner,
    owned: owner != Packages::UNOWNED,
    dependencies: dependency_names,

    # Used for future implementations of NestedPacks
    parent_name: parent_name
  }

  keys.nil? ? all_values : all_values.slice(*T.unsafe(keys))
end

#dependenciesObject



45
46
47
# File 'lib/query_packwerk/package.rb', line 45

def dependencies
  Packages.where(name: @original_package.dependencies)
end

#dependency_namesObject



50
51
52
# File 'lib/query_packwerk/package.rb', line 50

def dependency_names
  @original_package.dependencies
end

#directoryObject



60
61
62
# File 'lib/query_packwerk/package.rb', line 60

def directory
  Pathname.new(name).cleanpath
end

#enforce_dependenciesObject



25
26
27
# File 'lib/query_packwerk/package.rb', line 25

def enforce_dependencies
  !!@original_package.enforce_dependencies
end

#enforce_privacyObject



30
31
32
# File 'lib/query_packwerk/package.rb', line 30

def enforce_privacy
  !!@original_package.enforce_privacy
end

#inspectObject



125
126
127
# File 'lib/query_packwerk/package.rb', line 125

def inspect
  "#<#{self.class.name} #{name}>"
end

#metadataObject



35
36
37
# File 'lib/query_packwerk/package.rb', line 35

def 
  @original_package.
end

#nameObject



20
21
22
# File 'lib/query_packwerk/package.rb', line 20

def name
  @original_package.name
end

#ownerObject



55
56
57
# File 'lib/query_packwerk/package.rb', line 55

def owner
  config['owner'] || Packages::UNOWNED
end

#parent_nameObject



101
102
103
# File 'lib/query_packwerk/package.rb', line 101

def parent_name
  directory.dirname.to_s
end

#todosObject Also known as: outgoing_violations



68
69
70
# File 'lib/query_packwerk/package.rb', line 68

def todos
  QueryPackwerk::Violations.where(consuming_pack: name)
end

#violationsObject Also known as: incoming_violations



77
78
79
# File 'lib/query_packwerk/package.rb', line 77

def violations
  QueryPackwerk::Violations.where(producing_pack: name)
end