Class: Pod::Shell
- Inherits:
-
Object
- Object
- Pod::Shell
- Defined in:
- lib/podfileDep/thin/shell.rb
Instance Attribute Summary collapse
-
#project_shell ⇒ Object
壳工程project对象.
-
#reference_files ⇒ Pathname
壳工程引用的文件列表.
-
#reference_pods ⇒ String
壳工程引用的依赖库.
Instance Method Summary collapse
-
#deps_shell ⇒ String
获取壳工程所引用的依赖库.
-
#init_project_shell ⇒ Object
初始化project对象.
-
#initialize ⇒ Shell
constructor
A new instance of Shell.
-
#pod_in_file(file_path) ⇒ Object
获取某个文件里引用的依赖库名字.
-
#reference_code_file(group) ⇒ Object
获取其对应的引用代码文件和路径.
Constructor Details
#initialize ⇒ Shell
Returns a new instance of Shell.
7 8 9 10 11 |
# File 'lib/podfileDep/thin/shell.rb', line 7 def initialize super @reference_files = [] @reference_pods = [] end |
Instance Attribute Details
#project_shell ⇒ Object
壳工程project对象
15 16 17 |
# File 'lib/podfileDep/thin/shell.rb', line 15 def project_shell @project_shell end |
#reference_files ⇒ Pathname
壳工程引用的文件列表
19 20 21 |
# File 'lib/podfileDep/thin/shell.rb', line 19 def reference_files @reference_files end |
#reference_pods ⇒ String
壳工程引用的依赖库
23 24 25 |
# File 'lib/podfileDep/thin/shell.rb', line 23 def reference_pods @reference_pods end |
Instance Method Details
#deps_shell ⇒ String
获取壳工程所引用的依赖库
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/podfileDep/thin/shell.rb', line 27 def deps_shell init_project_shell reference_code_file(project_shell.root_object.main_group) reference_files.each do |reference_file| pod_in_file(reference_file) end reference_pods end |
#init_project_shell ⇒ Object
初始化project对象
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/podfileDep/thin/shell.rb', line 41 def init_project_shell xcodeproj_file = nil Dir.foreach(Dir.pwd) do |file| if file.end_with?(".xcodeproj") xcodeproj_file = file break end end xcodeproj_path = "#{Dir.pwd}/#{xcodeproj_file}" unless File.exist?(xcodeproj_path) return nil end @project_shell = Xcodeproj::Project.open(xcodeproj_path) end |
#pod_in_file(file_path) ⇒ Object
获取某个文件里引用的依赖库名字
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/podfileDep/thin/shell.rb', line 96 def pod_in_file(file_path) if File.directory?(file_path) return reference_pods end line_array = IO.readlines(file_path) line_array.each_with_index { |line| unless line.start_with?("#import <") next end unless line.include?("/") next end line_split_array = line.split("/") if line_split_array.size < 1 next end line_module_name = line_split_array[0].gsub("#import <","") real_module_name = line_module_name.include?("/") ? line_module_name.split("/")[0] : line_module_name #处理有子模块的情况 unless reference_pods.include?(real_module_name) reference_pods << real_module_name end } reference_pods end |
#reference_code_file(group) ⇒ Object
获取其对应的引用代码文件和路径
60 61 62 63 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 |
# File 'lib/podfileDep/thin/shell.rb', line 60 def reference_code_file(group) # 文件引用 file_reference = Xcodeproj::Project::Object::PBXFileReference group.children.each {|child| if child.class != file_reference self.reference_code_file(child) next end file_name = child.real_path.basename extend_name = file_name.extname if not extend_name == ".h" and not extend_name == ".m" and not extend_name == ".mm" and not extend_name == ".pch" and not extend_name == ".c" and not extend_name == ".cc" and not extend_name == ".hpp" and not extend_name == ".cpp" next end # 引用关系路径 hierarchy_path_array = child.hierarchy_path.split("/") if hierarchy_path_array.size < 2 next end reference_files << child.real_path } end |