Class: Foobara::RemoteGenerator::Generators::DependencyGroup
- Inherits:
-
Object
- Object
- Foobara::RemoteGenerator::Generators::DependencyGroup
- Defined in:
- foobara-typescript-remote-command-generator-1.3.1/src/generators/dependency_group.rb
Defined Under Namespace
Classes: CollisionData
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#deps_are_for ⇒ Object
Returns the value of attribute deps_are_for.
-
#name ⇒ Object
Returns the value of attribute name.
-
#will_define ⇒ Object
Returns the value of attribute will_define.
-
#winners ⇒ Object
Returns the value of attribute winners.
Instance Method Summary collapse
- #collision_data ⇒ Object
- #collision_data_for(dep) ⇒ Object
-
#initialize(dependencies, name:, deps_are_for:, will_define:, winners: nil) ⇒ DependencyGroup
constructor
A new instance of DependencyGroup.
- #non_colliding_dependency_roots ⇒ Object
- #non_colliding_root(dep) ⇒ Object
- #non_colliding_type(dep, points = points_for(dep)) ⇒ Object
- #non_colliding_type_name(dep, points = points_for(dep)) ⇒ Object
- #non_colliding_type_path(dep, points = points_for(dep)) ⇒ Object
- #points_for(dep) ⇒ Object
- #raw_points_for(dep) ⇒ Object
- #set_collision_data_for(dep, collision_data) ⇒ Object
- #to_key(dep) ⇒ Object
Constructor Details
#initialize(dependencies, name:, deps_are_for:, will_define:, winners: nil) ⇒ DependencyGroup
Returns a new instance of DependencyGroup.
15 16 17 18 19 20 21 22 23 |
# File 'src/generators/dependency_group.rb', line 15 def initialize(dependencies, name:, deps_are_for:, will_define:, winners: nil) self.deps_are_for = deps_are_for self.will_define = will_define self.name = name self.dependencies = dependencies.to_set self.winners = [*winners] if winners find_collisions end |
Instance Attribute Details
#dependencies ⇒ Object
Returns the value of attribute dependencies.
13 14 15 |
# File 'src/generators/dependency_group.rb', line 13 def dependencies @dependencies end |
#deps_are_for ⇒ Object
Returns the value of attribute deps_are_for.
13 14 15 |
# File 'src/generators/dependency_group.rb', line 13 def deps_are_for @deps_are_for end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'src/generators/dependency_group.rb', line 13 def name @name end |
#will_define ⇒ Object
Returns the value of attribute will_define.
13 14 15 |
# File 'src/generators/dependency_group.rb', line 13 def will_define @will_define end |
#winners ⇒ Object
Returns the value of attribute winners.
13 14 15 |
# File 'src/generators/dependency_group.rb', line 13 def winners @winners end |
Instance Method Details
#collision_data ⇒ Object
46 47 48 |
# File 'src/generators/dependency_group.rb', line 46 def collision_data @collision_data ||= {} end |
#collision_data_for(dep) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'src/generators/dependency_group.rb', line 25 def collision_data_for(dep) key = to_key(dep) collision_data[key].tap do |cd| unless cd # :nocov: raise "Dependency #{dep} is not part of this dependency group" # :nocov: end end end |
#non_colliding_dependency_roots ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'src/generators/dependency_group.rb', line 50 def non_colliding_dependency_roots roots = Set.new dependencies.each do |dep| roots << non_colliding_root(dep) end roots end |
#non_colliding_root(dep) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'src/generators/dependency_group.rb', line 60 def non_colliding_root(dep) root = dep points = points_for(dep) points_climbed = dep.ts_instance_path.size until points_climbed >= points points_climbed += dep.ts_instance_path.size root = root.parent end root end |
#non_colliding_type(dep, points = points_for(dep)) ⇒ Object
97 98 99 |
# File 'src/generators/dependency_group.rb', line 97 def non_colliding_type(dep, points = points_for(dep)) non_colliding_type_name(dep, points) end |
#non_colliding_type_name(dep, points = points_for(dep)) ⇒ Object
93 94 95 |
# File 'src/generators/dependency_group.rb', line 93 def non_colliding_type_name(dep, points = points_for(dep)) non_colliding_type_path(dep, points).join(".") end |
#non_colliding_type_path(dep, points = points_for(dep)) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'src/generators/dependency_group.rb', line 101 def non_colliding_type_path(dep, points = points_for(dep)) if points == 0 path = dep.ts_instance_path return path.size == 1 ? path : [path.last] end path = dep.ts_instance_path paths = [path] points_climbed = path.size until points_climbed >= points dep = dep.parent break unless dep path = dep.ts_instance_path paths.unshift(path) points_climbed += path.size end paths.flatten end |
#points_for(dep) ⇒ Object
85 86 87 88 89 90 91 |
# File 'src/generators/dependency_group.rb', line 85 def points_for(dep) if winners&.include?(dep) 0 else raw_points_for(dep) end end |
#raw_points_for(dep) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'src/generators/dependency_group.rb', line 73 def raw_points_for(dep) points = collision_data_for(dep).points unless points # :nocov: raise "Dependency #{dep} has no collision data" # :nocov: end points end |
#set_collision_data_for(dep, collision_data) ⇒ Object
37 38 39 40 |
# File 'src/generators/dependency_group.rb', line 37 def set_collision_data_for(dep, collision_data) key = to_key(dep) self.collision_data[key] = collision_data end |
#to_key(dep) ⇒ Object
42 43 44 |
# File 'src/generators/dependency_group.rb', line 42 def to_key(dep) [dep.scoped_category, *dep.ts_instance_full_path].map(&:to_s) end |