Class: ModularizationStatistics::Private::Metrics::NestedPacks::PackGroup
- Inherits:
-
T::Struct
- Object
- T::Struct
- ModularizationStatistics::Private::Metrics::NestedPacks::PackGroup
- Extended by:
- T::Sig
- Defined in:
- lib/modularization_statistics/private/metrics/nested_packs.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.all_from(packages) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/modularization_statistics/private/metrics/nested_packs.rb', line 18 def self.all_from(packages) packs_by_group = {} packages.each do |package| # For a child pack, package.directory is `packs/fruits/apples` (i.e. the directory of the package.yml file). # The package.directory.dirname is therefore `packs/fruits`. # For a standalone pack, package.directory.dirname is `packs` # A pack with no parent is in a pack group of its own name root = ParsePackwerk.find(package.directory.dirname.to_s) || package # Mark the parent pack and child pack as being in the pack group of the parent packs_by_group[root.name] ||= { root: root, members: [] } packs_by_group[root.name][:members] << package end packs_by_group.map do |name, pack_data| PackGroup.new( name: name, root: pack_data[:root], members: pack_data[:members], ) end end |
Instance Method Details
#children_pack_count ⇒ Object
42 43 44 45 46 |
# File 'lib/modularization_statistics/private/metrics/nested_packs.rb', line 42 def children_pack_count members.count do |package| package.name != root.name end end |
#cross_group_violations ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/modularization_statistics/private/metrics/nested_packs.rb', line 54 def cross_group_violations all_violations = members.flat_map do |member| ParsePackwerk::DeprecatedReferences.for(member).violations end all_violations.select do |violation| !members.map(&:name).include?(violation.to_package_name) end end |
#has_parent? ⇒ Boolean
49 50 51 |
# File 'lib/modularization_statistics/private/metrics/nested_packs.rb', line 49 def has_parent? children_pack_count > 0 end |