Class: Foobara::RemoteGenerator::Services::DependencyGroup

Inherits:
Object
  • Object
show all
Defined in:
foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/dependency_group.rb

Defined Under Namespace

Classes: CollisionData

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependencies, name:) ⇒ DependencyGroup

Returns a new instance of DependencyGroup.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/dependency_group.rb', line 15

def initialize(dependencies, name:)
  self.name = name
  self.dependencies = dependencies.to_set

  dependencies.each do |dep|
    if dep.belongs_to_dependency_group
      # :nocov:
      raise "Dependency group #{dep} already belongs to dependency group #{dep.dependency_group}"
      # :nocov:
    end

    dep.belongs_to_dependency_group = self
  end

  find_collisions
end

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



13
14
15
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/dependency_group.rb', line 13

def dependencies
  @dependencies
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/dependency_group.rb', line 13

def name
  @name
end

Instance Method Details

#collision_dataObject



53
54
55
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/dependency_group.rb', line 53

def collision_data
  @collision_data ||= {}
end

#collision_data_for(dep) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/dependency_group.rb', line 32

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_rootsObject



57
58
59
60
61
62
63
64
65
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/dependency_group.rb', line 57

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



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/dependency_group.rb', line 67

def non_colliding_root(dep)
  root = dep
  points = points_for(dep)
  points_climbed = 0

  until points_climbed >= points
    # TODO: can't use scoped_path because sometimes we want UnloadedUser instead of User. How to fix??
    points_climbed += dep.scoped_path.size
    root = root.parent
  end

  root
end

#non_colliding_type(dep, points = points_for(dep)) ⇒ Object



97
98
99
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/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 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/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
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/dependency_group.rb', line 101

def non_colliding_type_path(dep, points = points_for(dep))
  start_at = dep.ts_type_full_path.size - points - 1
  path = dep.ts_type_full_path[start_at..] || []

  path.map(&:to_s)
end

#points_for(dep) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/dependency_group.rb', line 81

def 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



44
45
46
47
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/dependency_group.rb', line 44

def set_collision_data_for(dep, collision_data)
  key = to_key(dep)
  self.collision_data[key] = collision_data
end

#to_key(dep) ⇒ Object



49
50
51
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/dependency_group.rb', line 49

def to_key(dep)
  [dep.scoped_category, *dep.ts_instance_full_path].map(&:to_s)
end