Class: PodsOrz::PodsSort
- Inherits:
-
Object
- Object
- PodsOrz::PodsSort
- Defined in:
- lib/podsorz/core/PodsOrz/pods_sort.rb
Instance Method Summary collapse
- #recursive_puts(key, array, pathArray) ⇒ Object
- #sort(pods_list, kx_pods_subPath) ⇒ Object
- #sort_with_hash ⇒ Object
- #spec_with_path(path, fileName) ⇒ Object
Instance Method Details
#recursive_puts(key, array, pathArray) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/podsorz/core/PodsOrz/pods_sort.rb', line 64 def recursive_puts(key,array,pathArray) # pathArray << key totalArray = [] if array.empty? # puts ("kong - #{key}") else array.each {|line| pathArray << line priority = @@fileHash[line] + 1 @@fileHash[line] = priority tempArray = @@filterHash[line] if tempArray.empty? pathArray.pop else cycle = false tempArray.each {|podsName| if pathArray.include?(podsName) cycle = true Logger.error("path:#{pathArray} pod:#{podsName} has dependence cycle, please fix cycle") exit() end # priorityN = @@fileHash[podsName] + 1 # puts("次数 podsName #{podsName} #{priorityN}") # @@fileHash[podsName] = priorityN } if cycle #包含 # puts pathArray else # puts ("#{key} #{line} #{pathArray}") recursive_puts(line,tempArray,pathArray) pathArray.pop end end } end end |
#sort(pods_list, kx_pods_subPath) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/podsorz/core/PodsOrz/pods_sort.rb', line 8 def sort(pods_list,kx_pods_subPath) # file priority 1 hash @@fileHash = {} # podspec hash @@podspecHash = {} @@filterHash = {} pods_list.each { |fileName| @@fileHash[fileName] = 1 } pods_list.each { |fileName| filePath = "#{kx_pods_subPath}/#{fileName}" is_directory = File.directory?(filePath) if is_directory spec_with_path("#{filePath}/#{fileName}.podspec",fileName) else Logger.warning("#{filePath} is an empty file") end } sort_with_hash() @resultHash = {} @@filterHash.each { |fileName,array| # puts ("#{fileName},#{array}") recursive_puts(fileName,array,[fileName]) } @@fileHash.each {|file,priority| # puts ("#{file} #{priority}") if @resultHash.key?(priority) array = @resultHash[priority] array << file @resultHash[priority] = array else @resultHash[priority] = [file] end } sortList = [] checkHash = {} # puts @resultHash @resultHash.sort.sort!.each { |priority,array| # puts ("#{priority},#{array}") array.each { |line| puts ("#{priority} -- #{line}") checkHash[line] = priority sortList << line } } sortList.reverse! end |
#sort_with_hash ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/podsorz/core/PodsOrz/pods_sort.rb', line 111 def sort_with_hash() @@podspecHash.each { |fileName,specArray| # puts "#{fileName} #{specArray}" tempArray = [] @@fileHash.each {|file,priority| specArray.each { |line| if line.include? "dependency" if line.include? file and file != fileName priority += 1 # @@fileHash[file] = priority tempArray << file # puts "#{fileName},#{file},#{line}" end end } } @@filterHash[fileName] = tempArray } end |
#spec_with_path(path, fileName) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/podsorz/core/PodsOrz/pods_sort.rb', line 140 def spec_with_path(path,fileName) return if path.nil? path = Pathname.new(path) path = Pathname.new(Dir.pwd).join(path) unless path.absolute? return unless path.exist? @path = path. arr = IO.readlines("#{@path}") @@podspecHash[fileName] = arr end |