Class: Pod::DepFinder
- Inherits:
-
Object
- Object
- Pod::DepFinder
- Defined in:
- lib/core_blur/dep/find.rb
Instance Attribute Summary collapse
-
#find_name ⇒ Object
Returns the value of attribute find_name.
-
#forward ⇒ Object
Returns the value of attribute forward.
-
#lockfile_content ⇒ Object
Returns the value of attribute lockfile_content.
-
#sort_count ⇒ Object
Returns the value of attribute sort_count.
Instance Method Summary collapse
- #find ⇒ Object
- #find_all_dep ⇒ Object
- #find_forward_with_name(name) ⇒ Object
- #find_reverse_with_name(name) ⇒ Object
- #find_single_dep ⇒ Object
- #init_lock ⇒ Object
-
#initialize ⇒ DepFinder
constructor
A new instance of DepFinder.
Constructor Details
#initialize ⇒ DepFinder
Returns a new instance of DepFinder.
9 10 11 12 |
# File 'lib/core_blur/dep/find.rb', line 9 def initialize super init_lock end |
Instance Attribute Details
#find_name ⇒ Object
Returns the value of attribute find_name.
6 7 8 |
# File 'lib/core_blur/dep/find.rb', line 6 def find_name @find_name end |
#forward ⇒ Object
Returns the value of attribute forward.
8 9 10 |
# File 'lib/core_blur/dep/find.rb', line 8 def forward @forward end |
#lockfile_content ⇒ Object
Returns the value of attribute lockfile_content.
5 6 7 |
# File 'lib/core_blur/dep/find.rb', line 5 def lockfile_content @lockfile_content end |
#sort_count ⇒ Object
Returns the value of attribute sort_count.
7 8 9 |
# File 'lib/core_blur/dep/find.rb', line 7 def sort_count @sort_count end |
Instance Method Details
#find ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/core_blur/dep/find.rb', line 20 def find if @find_name find_single_dep else find_all_dep end puts "\n基础命令(默认输出反向依赖):pod dep" unless @forward puts "==> 输出所有正向依赖,可加参数 --forward".yellow end unless @sort_count puts "==> 按数量从少到多排序,可加参数 --sort".yellow end unless @find_name puts "==> 查询单个依赖的情况,可使用参数 --name=xx".yellow end end |
#find_all_dep ⇒ Object
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 62 63 64 65 66 |
# File 'lib/core_blur/dep/find.rb', line 37 def find_all_dep result_map = Hash.new @lockfile_content['PODS'].each do |pod| key = pod.is_a?(Hash) ? pod.keys[0] : pod key = key.split(" (")[0] if @forward result_map[key] = pod.is_a?(Hash) ? pod.values[0] : Array.new else result_map[key] = find_reverse_with_name(key) end end msg = @forward ? "正向依赖" : "反向依赖" puts "打印#{msg}" sorted_hash = result_map if @sort_count puts "数量从少到多" sorted_hash = Hash[result_map.sort_by { |key, value| value.length }] end sorted_hash.each do |key, array| if @forward puts "组件#{key}的依赖有(#{array.length}个):".green else puts "依赖#{key}的组件有(#{array.length}个):".green end array.each do |obj| puts obj end puts "\n" end end |
#find_forward_with_name(name) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/core_blur/dep/find.rb', line 80 def find_forward_with_name(name) if not @lockfile_content or not @lockfile_content['PODS'] return [] end results = Array.new @lockfile_content['PODS'].each do |pod| key = pod.is_a?(Hash) ? pod.keys[0] : pod key = key.split(" (")[0] if key == name and pod.is_a?(Hash) pod.each_value do |value| results << value end end end results end |
#find_reverse_with_name(name) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/core_blur/dep/find.rb', line 96 def find_reverse_with_name(name) if not @lockfile_content or not @lockfile_content['PODS'] return [] end results = Array.new @lockfile_content['PODS'].each do |pod| if pod.is_a?(Hash) pod.values.each do |value| if value.is_a?(Array) value.each { |sub_value| sub_module = sub_value.split(" (")[0] if sub_module == name results << pod.keys.first end } end end end end results.uniq end |
#find_single_dep ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/core_blur/dep/find.rb', line 67 def find_single_dep results = find_reverse_with_name(@find_name) puts "依赖#{@find_name}的组件有(#{results.length}个):".green results.each do |res| puts res end puts "\n" forward_results = find_forward_with_name(@find_name) puts "#{@find_name}依赖的组件有(#{forward_results.length}个):".green forward_results.each do |res| puts res end end |
#init_lock ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/core_blur/dep/find.rb', line 13 def init_lock unless File.exist?("Podfile.lock") puts "Podfile.lock文件不存在,请先执行pod install或pod update".red end @sort_count = false @lockfile_content = YAML.load_file('Podfile.lock') end |