Class: Xcodeproj::ImportChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/core_blur/check/import.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ ImportChecker

Returns a new instance of ImportChecker.



5
6
7
# File 'lib/core_blur/check/import.rb', line 5

def initialize(project)
  @project = project
end

Instance Attribute Details

#projectObject

Returns the value of attribute project.



4
5
6
# File 'lib/core_blur/check/import.rb', line 4

def project
  @project
end

Instance Method Details

#check_importObject



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
# File 'lib/core_blur/check/import.rb', line 8

def check_import
  puts "import检查中..."
  start = (Time.now.to_f * 1000).to_i
  module_count = 0
  file_count = 0
  project.module_items.each do |module_name, module_item|
    unless module_item.is_development_module
      next
    end
    module_count += 1
    messages = []
    did_check_imports = {}
    module_item.init_import_info
    module_item.import_items.each do |import_item|
      file_count += 1
      did_check_import = did_check_imports[import_item.import_file_name]
      if did_check_import
        next
      end
      need_module_item = project.module_items[import_item.module_name]
      real_path = need_module_item.header_files[import_item.import_file_name]
      did_check_imports[import_item.import_file_name] = !!(real_path)
      unless real_path
        expect_module_name = find_module_with_header_file(import_item.import_file_name)
        if expect_module_name
          messages << "#{import_item.file_path.basename}#{import_item.line_index}#{import_item.import_name} => #import <#{expect_module_name}/#{import_item.import_file_name}>"
        end
      end
    end
    if messages.size >0
      puts "组件#{module_item.module_name}存在以下情况, 请检查:".yellow
      puts messages
      puts "\n"
    end
  end
  duration = ((Time.now.to_f * 1000).to_i - start)*0.001
  puts "import检查完毕! 共检查#{module_count}个组件(#{file_count}个import) 耗时:#{duration.round(2)}"
end