Class: TYCiCore::TYPodAnalyse

Inherits:
Object
  • Object
show all
Defined in:
lib/tuya/ci/core/dependencies/node/podfile_lock_analyse.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(podfile_lock) ⇒ TYPodAnalyse

Returns a new instance of TYPodAnalyse.



4
5
6
7
8
9
10
11
12
13
# File 'lib/tuya/ci/core/dependencies/node/podfile_lock_analyse.rb', line 4

def initialize(podfile_lock)
  @pods_hash = Hash.new
  @pod_nodes_hash = Hash.new
  @podfile_lock = podfile_lock
  podfile_lock.all_pods.each do |pod|
    pod_item = TYPodItem.new pod
    pod_item.dependency_list = @podfile_lock.pods[pod]
    @pods_hash[pod] = pod_item
  end
end

Instance Attribute Details

#pod_nodes_hashObject

Returns the value of attribute pod_nodes_hash.



3
4
5
# File 'lib/tuya/ci/core/dependencies/node/podfile_lock_analyse.rb', line 3

def pod_nodes_hash
  @pod_nodes_hash
end

#podfile_lockObject

Returns the value of attribute podfile_lock.



3
4
5
# File 'lib/tuya/ci/core/dependencies/node/podfile_lock_analyse.rb', line 3

def podfile_lock
  @podfile_lock
end

#pods_hashObject

Returns the value of attribute pods_hash.



3
4
5
# File 'lib/tuya/ci/core/dependencies/node/podfile_lock_analyse.rb', line 3

def pods_hash
  @pods_hash
end

Instance Method Details

#dep_node(node) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/tuya/ci/core/dependencies/node/podfile_lock_analyse.rb', line 60

def dep_node(node)
  if !node || !node.nodes || node.nodes.size == 0
    return 0
  end
  dep = []
  node.nodes.keys.each do |name|
    child_node = node.nodes[name]
    dep.push((dep_node child_node) + 1)
  end
  max_dep = dep.max
  node.node_dep = max_dep
  node.node_dep
end

#dep_treeObject



53
54
55
56
57
58
# File 'lib/tuya/ci/core/dependencies/node/podfile_lock_analyse.rb', line 53

def dep_tree
  @pods_hash.keys.each do |name|
    child_node = @pod_nodes_hash[name]
    dep_node child_node
  end
end

#diplomatic_podsObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/tuya/ci/core/dependencies/node/podfile_lock_analyse.rb', line 80

def diplomatic_pods
  sort_nodes
  pods_ = []
  @pod_nodes_hash.keys.each do |key|
    pods_ << (level_order_node @pod_nodes_hash[key])
  end
  pods_hash = Hash.new
  pods_.each do |pods|
    order = pods_hash[pods.size]
    if order
      order.pods = order.pods + pods
    else
      pods_hash[pods.size] = TYPodOrder.new pods.size, pods
    end
  end
  pods_keys_sort = pods_hash.keys.sort.reverse
  result = []
  pods_keys_sort.each do |key|
    pods = pods_hash[key].pods
    result += pods
  end
  result.uniq
end

#level_order_node(node) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/tuya/ci/core/dependencies/node/podfile_lock_analyse.rb', line 104

def level_order_node(node)
  result = []
  queue = []
  queue.push node
  while queue.size > 0 do
    target_node = queue[0]
    queue.delete_at 0
    result.insert 0,target_node.pod_item.name
    target_node.nodes.keys.each do |key_node|
      queue.push target_node.nodes[key_node] if target_node.nodes[key_node]
    end
  end
  result.uniq
end

#sort_nodesObject



74
75
76
77
78
# File 'lib/tuya/ci/core/dependencies/node/podfile_lock_analyse.rb', line 74

def sort_nodes
  @pod_nodes_hash.sort_by do |k, v|
    v.node_dep
  end
end

#sorted_podsObject



15
16
17
18
19
# File 'lib/tuya/ci/core/dependencies/node/podfile_lock_analyse.rb', line 15

def sorted_pods
  trees
  dep_tree
  diplomatic_pods
end

#tree_build(root_node, root_item) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/tuya/ci/core/dependencies/node/podfile_lock_analyse.rb', line 30

def tree_build(root_node, root_item)
  root_node.add_pod_item root_item
  root_item.dependency = true
  if root_item.dependency_list
    root_item.dependency_list.each do |item|
      child_item = @pods_hash[item]
      if child_item
        child_node = @pod_nodes_hash[child_item.name]
        if child_node
          unless child_node.parent
            @pod_nodes_hash.delete child_node.pod_item.name
            root_node.join_node child_node
          end
        else
          child_node = TYPodNode.new
          root_node.join_node tree_build(child_node, child_item)
        end
      end
    end
  end
  root_node
end

#treesObject



21
22
23
24
25
26
27
28
# File 'lib/tuya/ci/core/dependencies/node/podfile_lock_analyse.rb', line 21

def trees
  @podfile_lock.all_pods.each do |pod_name|
    pod_item = @pods_hash[pod_name]
    unless pod_item.dependency
      @pod_nodes_hash[pod_name] = tree_build TYPodNode.new, pod_item
    end
  end
end