class TYCiCore::TYPodAnalyse

Attributes

pod_nodes_hash[RW]
podfile_lock[RW]
pods_hash[RW]

Public Class Methods

new(podfile_lock) click to toggle source
# 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

Public Instance Methods

dep_node(node) click to toggle source
# 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_tree() click to toggle source
# 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_pods() click to toggle source
# 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) click to toggle source
# 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_nodes() click to toggle source
# 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_pods() click to toggle source
# 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) click to toggle source
# 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
trees() click to toggle source
# 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