Class: Dongjia::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/dongjia_router.rb

Instance Method Summary collapse

Instance Method Details

#route_items_from_file(path) ⇒ Object



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
# File 'lib/dongjia_router.rb', line 63

def route_items_from_file(path)
  route_items = []
  item = nil
  File.open(path, 'r') do |file|
    pre_line = nil
    file.each_line do |line|
      is_start = false
      if line.start_with?('@redirect')
        item = RouterItem.new(line)
        item.pre_line = pre_line
        is_start = true
      elsif item != nil && line.start_with?('}')
        item.body << line
        route_items << item
        item = nil
        pre_line = nil
      end
      if item != nil
        if !is_start
          item.body << line
        end
      end
      pre_line = line
    end
  end
  route_items
end

#scrape_routers(sandbox_root, config) ⇒ Object



91
92
93
94
95
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/dongjia_router.rb', line 91

def scrape_routers(sandbox_root, config)

  if config == nil
    return
  end

  result_file_path = ''
  path = config[:path]
  if path && path.length > 0
    result_file_path = File.expand_path(File.join(sandbox_root, '..', path))
  end
  if !File.exist?(result_file_path)
    Pod::UI.warn("Router scrapy: path not found.")
    return
  end

  route_items = []

  Dir.foreach(sandbox_root).select{|f| f.end_with?('xcodeproj')}.each do |name|
    proj = Xcodeproj::Project.open(File.join(sandbox_root, name))
    if name != 'Pods.xcodeproj'
      proj.targets.each do |target|
        next unless target.name.start_with?('DJ')
        next unless target.is_a?(Xcodeproj::Project::Object::PBXNativeTarget)
        target.source_build_phase.files_references.each do |file|
          next if file.path.end_with?('Api.m')
          next if file.path.end_with?('Model.m')
          next if file.path.end_with?('-dummy.m')
          next if file.path.end_with?('Log.m')
          route_items += route_items_from_file(file.real_path)
        end
      end
    end
  end

  # 排序
  route_items.sort! do |a, b|
    a.redirect_type.to_i <=> b.redirect_type.to_i
  end

  # 输出所有结果
  result = HEADER_CONTENT
  route_items.each do |item|
    result += item.output
  end

  FileUtils.chmod('u+w', result_file_path)

  File.open(result_file_path, 'w') do |f|
    f.write(result)
  end

  # 将文件只读
  FileUtils.chmod('ugo-w', result_file_path)

end