class CarthagePods::CocoaPodsManage

Public Instance Methods

generatePodspec() click to toggle source
# File lib/DependencyManagerTools/CocoaPods/CocoaPodsManage.rb, line 47
def generatePodspec

  version = getPlatformVersion
  platformType = getPlatformType
  data = {}
  data[:version] = version
  data[:platformType] = platformType

  podspec = spec_template data

  podspecFile = File.new('CarthagePods.podspec', 'w+')

  podspecFile.write podspec

  podspecFile.close

end
getPlatformType() click to toggle source
# File lib/DependencyManagerTools/CocoaPods/CocoaPodsManage.rb, line 84
def getPlatformType

  readPodfile do |line|

    if line =~ /^\s*platform\s*:(\w*)\s*,\s*['"]\d*.\d*'\s*$/
      reslut = /^\s*platform\s*:(\w*)\s*,\s*['"]\d*.\d*'\s*$/.match(line)
      return reslut[1]
    end

  end

  return 'ios'

end
getPlatformVersion() click to toggle source
# File lib/DependencyManagerTools/CocoaPods/CocoaPodsManage.rb, line 99
def getPlatformVersion

  readPodfile do |line|

    if line =~ /^\s*platform\s*:\w*\s*,\s*(['"]\d*.\d*['"])\s*$/
      reslut = /^\s*platform\s*:\w*\s*,\s*(['"]\d*.\d*['"])\s*$/.match(line)
      return reslut[1]
    end

  end

  return '\'9.0\''

end
insertCarthagePods() click to toggle source
# File lib/DependencyManagerTools/CocoaPods/CocoaPodsManage.rb, line 114
def insertCarthagePods

  podfile = File.new('Podfile', 'r')

  curPodfile = podfile.readlines

  podfile.close

  targetNum = 0

  newPodFile = ''

  @podfileText = ""

  for line in curPodfile

    @podfileText += line

    if (line =~ /^\s*target\s*['"]\w*['"]\s*do\s*$/)
      targetNum += 1
      newPodFile += line
      next
    end

    if (line =~ /^\s*end\s*$/) && targetNum > 0

      targetNum -= 1

      if targetNum == 0
        newPodFile += ("pod 'CarthagePods', :path => './'\n")
      end

      newPodFile += line

      next

    end

    newPodFile += line

  end

  podfile = File.new('Podfile', 'w+')

  podfile.write newPodFile

  podfile.close

end
install(arg={}) click to toggle source
# File lib/DependencyManagerTools/CocoaPods/CocoaPodsManage.rb, line 174
def install(arg={})

  insertCarthagePods

  cmdObj = TTY::Command.new

  cmd = argMarge('pod install', arg)

  cmdObj.run cmd

  reductionPodfile

end
platformToCarthagePath(type) click to toggle source
# File lib/DependencyManagerTools/CocoaPods/CocoaPodsManage.rb, line 9
def platformToCarthagePath(type)

  case type
    when 'osx'
      return 'Mac'
    when 'ios'
      return 'iOS'
    when 'tvos'
      return 'tvOS'
    when 'watchos'
      return 'watchOS'
    else
      return 'iOS'

  end

end
readPodfile() { |line| ... } click to toggle source
# File lib/DependencyManagerTools/CocoaPods/CocoaPodsManage.rb, line 65
def readPodfile

  podfile = File.new('Podfile', 'r')

  lines = podfile.readlines

  podfile.close

  for line in lines

    if line =~ /0?(#)/
      next
    end

    yield line
  end

end
reductionPodfile() click to toggle source
# File lib/DependencyManagerTools/CocoaPods/CocoaPodsManage.rb, line 164
def reductionPodfile

  podfile = File.new('Podfile', 'w+')

  podfile.write @podfileText

  podfile.close

end
spec_template(data) click to toggle source
# File lib/DependencyManagerTools/CocoaPods/CocoaPodsManage.rb, line 27
    def spec_template(data)
      <<-SPEC
Pod::Spec.new do |s|
  s.name         = 'CarthagePods'
  s.version      = '1.0'
  s.summary      = 'A short description of CarthagePods.'
  s.description  = <<-DESC
                    LICENSE
                   DESC
  s.homepage     = 'http://EXAMPLE/CarthagePods'
  s.license      = 'MIT'
  s.author             = { 'CarthagePods' => 'CarthagePods@CarthagePods.com' }
  s.platform     = :#{data[:platformType]}, #{data[:version]}
  s.source       = { :git => 'https://github.com/bay2/CarthagePods.git', :tag => '1.0' }
  s.vendored_frameworks = 'Carthage/Build/#{platformToCarthagePath(data[:platformType])}/*.framework'
end
      SPEC

    end
update(arg={}) click to toggle source
# File lib/DependencyManagerTools/CocoaPods/CocoaPodsManage.rb, line 188
def update(arg={})

  cmdObj = TTY::Command.new

  cmd = argMarge('pod update', arg)

  cmdObj.run cmd

end