Class: DYAutomate::Command::Pod
- Inherits:
-
DYAutomate::Command
- Object
- CLAide::Command
- DYAutomate::Command
- DYAutomate::Command::Pod
- Defined in:
- lib/DYAutomate/Command/pod.rb,
lib/DYAutomate/Command/Pod/push.rb,
lib/DYAutomate/Command/Pod/version.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#name ⇒ Object
lib名字.
-
#path ⇒ Object
当前路径.
-
#spec_name ⇒ Object
#查询结果lib信息.
-
#spec_path ⇒ Object
spec文件路径.
Attributes inherited from DYAutomate::Command
Instance Method Summary collapse
-
#dy_update_repo ⇒ Object
更新repo.
-
#existPodspec? ⇒ Boolean
podspec文件是否存在.
-
#file_line_match(path, reg) ⇒ Object
文本文件查找内容.
-
#file_line_match_replace(path, reg, newline) ⇒ Object
文本文件替换某一行中文本.
-
#get_spec_version ⇒ Object
查找spec中版本号.
-
#get_version_big_new ⇒ Object
1.1.1 => 1.2.0.
-
#get_version_new ⇒ Object
1.1.1 => 1.1.2.
-
#initialize(argv) ⇒ Pod
constructor
A new instance of Pod.
- #run ⇒ Object
- #validate! ⇒ Object
Methods inherited from DYAutomate::Command
Constructor Details
#initialize(argv) ⇒ Pod
Returns a new instance of Pod.
26 27 28 29 30 |
# File 'lib/DYAutomate/Command/pod.rb', line 26 def initialize(argv) super @path = Dir.pwd pp("当前环境变量 #{@env_str}",1) end |
Instance Attribute Details
#name ⇒ Object
lib名字
17 18 19 |
# File 'lib/DYAutomate/Command/pod.rb', line 17 def name @name end |
#path ⇒ Object
当前路径
19 20 21 |
# File 'lib/DYAutomate/Command/pod.rb', line 19 def path @path end |
#spec_name ⇒ Object
#查询结果lib信息
24 25 26 |
# File 'lib/DYAutomate/Command/pod.rb', line 24 def spec_name @spec_name end |
#spec_path ⇒ Object
spec文件路径
22 23 24 |
# File 'lib/DYAutomate/Command/pod.rb', line 22 def spec_path @spec_path end |
Instance Method Details
#dy_update_repo ⇒ Object
更新repo
147 148 149 150 151 152 153 154 155 156 |
# File 'lib/DYAutomate/Command/pod.rb', line 147 def dy_update_repo path = File.join(Dir.home,'.cocoapods/repos') excludeFiles = [".","..",".DS_Store",'master','trunk'] Dir.entries(path).each do |subDir| puts subDir unless excludeFiles.include?(subDir) system "#{@env_str} pod repo update #{subDir}" end end end |
#existPodspec? ⇒ Boolean
podspec文件是否存在
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/DYAutomate/Command/pod.rb', line 47 def existPodspec? exist = false Dir.entries(@path).each{ |d| if d.to_s =~ /.podspec/ exist = true @spec_path = File.join(@path,d.to_s) @spec_name = d.to_s @name = d.to_s.split('.')[0] break end } exist end |
#file_line_match(path, reg) ⇒ Object
文本文件查找内容
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/DYAutomate/Command/pod.rb', line 113 def file_line_match(path,reg) pp('file_line_match ...' + path ,1) targetLine = '' File.open(path,"r+") do |file| #r:utf-8表示以utf-8编码读取文件,要与当前代码文件的编码相同 file.each_line {|line| puts line if line =~ reg targetLine = line break end } end pp('file_line_match..end --' + targetLine,1) targetLine end |
#file_line_match_replace(path, reg, newline) ⇒ Object
文本文件替换某一行中文本
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/DYAutomate/Command/pod.rb', line 130 def file_line_match_replace(path,reg,newline) filePath = path #查找要替换的文本 targetLine = file_line_match(filePath,reg) #替换内容 content = File.read(filePath) newContent = content.gsub(targetLine, newline) #覆盖内容 File.open(filePath,"w+") do |file| #r:utf-8表示以utf-8编码读取文件,要与当前代码文件的编码相同 file.write(newContent) file.close end end |
#get_spec_version ⇒ Object
查找spec中版本号
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/DYAutomate/Command/pod.rb', line 62 def get_spec_version #查找文本 targetLine = file_line_match(@spec_path,/s.version *=/) match = targetLine.match(/'[\d].[\d]*.[\d]*'/) v = '' if match v = match.to_s.gsub(/'/,'') end v end |
#get_version_big_new ⇒ Object
1.1.1 => 1.2.0
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/DYAutomate/Command/pod.rb', line 92 def get_version_big_new new_v = '' cur_v = get_spec_version pp(cur_v,1) if cur_v && cur_v.size > 0 new_v = cur_v.split('.').map.with_index{|x,i| if i == 1 x.to_i + 1 elsif i == 2 0 else x end }.join('.') end pp("get_version_big_new == #{new_v}",1) new_v end |
#get_version_new ⇒ Object
1.1.1 => 1.1.2
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/DYAutomate/Command/pod.rb', line 74 def get_version_new new_v = '' cur_v = get_spec_version pp(cur_v,1) if cur_v && cur_v.size > 0 new_v = cur_v.split('.').map.with_index{|x,i| if i == 2 x.to_i + 1 else x end }.join('.') end pp("get_version_new == #{new_v}",1) new_v end |
#run ⇒ Object
42 43 44 |
# File 'lib/DYAutomate/Command/pod.rb', line 42 def run pp('pod run ...',1) end |
#validate! ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/DYAutomate/Command/pod.rb', line 32 def validate! super unless existPodspec? help! " error -- >!!! has no podspec file at #{@path}" else puts "find podspec" + "#{@spec_path}" end end |