class DYAutomate::Command::Pod

Attributes

name[RW]

lib名字

path[RW]

当前路径

spec_name[RW]

查询结果lib信息

spec_path[RW]

spec文件路径

Public Class Methods

new(argv) click to toggle source
Calls superclass method DYAutomate::Command::new
# File lib/DYAutomate/Command/pod.rb, line 26
def initialize(argv)
  super
  @path = Dir.pwd
  pp("当前环境变量 #{@env_str}",1)
end

Public Instance Methods

dy_update_repo() click to toggle source

更新repo

# 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?() click to toggle source

podspec文件是否存在

# 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) click to toggle source

文本文件查找内容

# 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) click to toggle source

文本文件替换某一行中文本

# 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() click to toggle source

查找spec中版本号

# 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() click to toggle source

1.1.1 => 1.2.0

# 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() click to toggle source

1.1.1 => 1.1.2

# 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() click to toggle source
# File lib/DYAutomate/Command/pod.rb, line 42
def run
  pp('pod run ...',1)
end
validate!() click to toggle source
Calls superclass method
# 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