Class: Pod::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/core_blur/thin/shell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShell

Returns a new instance of Shell.



5
6
7
8
9
# File 'lib/core_blur/thin/shell.rb', line 5

def initialize
  super
  @reference_files = []
  @reference_pods = []
end

Instance Attribute Details

#project_shellObject

Returns the value of attribute project_shell.



10
11
12
# File 'lib/core_blur/thin/shell.rb', line 10

def project_shell
  @project_shell
end

#reference_filesObject

Returns the value of attribute reference_files.



11
12
13
# File 'lib/core_blur/thin/shell.rb', line 11

def reference_files
  @reference_files
end

#reference_podsObject

Returns the value of attribute reference_pods.



12
13
14
# File 'lib/core_blur/thin/shell.rb', line 12

def reference_pods
  @reference_pods
end

Instance Method Details

#deps_shellObject



13
14
15
16
17
18
19
20
# File 'lib/core_blur/thin/shell.rb', line 13

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_shellObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/core_blur/thin/shell.rb', line 21

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



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/core_blur/thin/shell.rb', line 61

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



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
# File 'lib/core_blur/thin/shell.rb', line 35

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