Class: Pod::Command::Bin::Import
Instance Method Summary
collapse
#validate!
#binary_spec, #binary_spec_files, #binary_template_spec, #binary_template_spec_file, #binary_template_spec_files, #clear_binary_spec_file_if_needed, #code_spec, #code_spec_files, #create_binary_spec_file, #find_spec_file, #spec_files
#binary_source, #code_source, #sources_manager, #sources_option, #valid_sources
Constructor Details
#initialize(argv) ⇒ Import
Returns a new instance of Import.
12
13
14
15
16
17
18
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 12
def initialize(argv)
@current_path = argv.shift_argument || Dir.pwd
@framework = argv.option('framework')
@header_map = {}
@header_folder_map = {}
super
end
|
Instance Method Details
68
69
70
71
72
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 68
def (folder)
= Dir.glob("#{pod_folder_name}/#{folder}/**/*.h")
.map! { |f| f.split('/').last }
end
|
#child_dir ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 60
def child_dir
dirs = Dir.entries(pod_folder_name)
dirs.reject! do |d|
File.directory?(d) || /\./ =~ d || /_Prebuild/ =~ d || /Target/ =~ d || /Headers/ =~ d || /Podspecs/ =~ d || framework_black_list.any?{ |f| f == d }
end
dirs
end
|
#exist_in_file(file, header) ⇒ Object
def format_string(file, line)
result = line
if /(\W)(TicketList)(\W)/ =~ line
result = result.gsub(/(\W)(TicketList)(\W)/, '\1TKTicketModel\3')
end
result
end
128
129
130
131
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 128
def exist_in_file(file, )
folder_name = @header_folder_map[.to_sym]
Regexp.new("/Pods/#{folder_name}") =~ File.path(file) if folder_name
end
|
#file_string(file) ⇒ Object
99
100
101
102
103
104
105
106
107
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 99
def file_string(file)
str = ''
File.open(file, 'r+') do |f|
f.each_line do |line|
str += format_string(f, line)
end
end
str
end
|
#find_all_sub_folder ⇒ Object
74
75
76
77
78
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 74
def find_all_sub_folder
Find.find(@current_path).each do |f|
handler_file f if f =~ /APPDelegate/
end
end
|
#find_head_key(line) ⇒ Object
133
134
135
136
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 133
def find_head_key(line)
= /"\D*.h"/
line.match()
end
|
109
110
111
112
113
114
115
116
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 109
def format_string(file, line)
result = line
if line =~ /#import/
ma = find_head_key(line)
result = line.gsub(ma[0], @header_map[ma[0].to_sym] || ma[0]) if ma && !exist_in_file(file, ma[0])
end
result
end
|
#framework_black_list ⇒ Object
46
47
48
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 46
def framework_black_list
%w[mob_sharesdk]
end
|
#framework_name_map ⇒ Object
42
43
44
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 42
def framework_name_map
{ 'lottie-ios': 'Lottie', 'UITableView+FDTemplateLayoutCell': 'UITableView_FDTemplateLayoutCell', 'mob_sharesdk': 'ShareSDK' }
end
|
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 28
def
= {}
folders = child_dir
folders.each { |name| [name] = (name) }
.each do |key, value|
value.each do ||
= "\"#{}\""
framework_name = framework_name_map[key.to_sym] || key
@header_map[.to_sym] = "<#{framework_name}/#{}>"
@header_folder_map[.to_sym] = key
end
end
end
|
#handler_file(file) ⇒ Object
90
91
92
93
94
95
96
97
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 90
def handler_file(file)
File.chmod(0o644, file)
str = file_string(file)
File.open(file, 'w+') do |f|
f.write(str)
end
File.chmod(0o444, file) if file =~ /Pods/
end
|
#pod_folder_name ⇒ Object
56
57
58
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 56
def pod_folder_name
File.directory?("#{@current_path}/Pods") ? "#{@current_path}/Pods" : "#{@current_path}/Example/Pods"
end
|
#run ⇒ Object
20
21
22
23
24
25
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 20
def run
end
|
50
51
52
53
54
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 50
def
@header_map.each do |key, value|
puts "#{key}===> #{value}"
end
end
|
80
81
82
83
84
85
86
87
88
|
# File 'lib/cocoapods-lhj-bin/command/bin/import.rb', line 80
def
Dir.glob("#{@current_path}/**/*.{m,h,pch}").each do |f|
if f =~ /Pods/
handler_file(f) if f =~ %r{Pods/ML}
else
handler_file(f)
end
end
end
|