class FWToolkit::Cocoapods

Public Instance Methods

install(project_root) click to toggle source
# File lib/fwtoolkit/cli/cocoapods.rb, line 17
def install(project_root)
  add_cocoapods_to_project project_root 
  if File.exists? File.join(project_root, 'Podfile')
    inside(project_root) {
        run! "bundle exec pod install", :capture => true
    }
  else
    say_status :skip, "Unable to locate the Podfile. Skipping pod install", :blue
  end
end
setup() click to toggle source
# File lib/fwtoolkit/cli/cocoapods.rb, line 11
def setup
  install_cocoapods_gem unless options[:'skip-install']
  setup_cocoapods_repos
end

Private Instance Methods

add_cocoapods_to_project(project_root) click to toggle source
# File lib/fwtoolkit/cli/cocoapods.rb, line 53
def add_cocoapods_to_project(project_root)
  gemfile = File.join(project_root, 'Gemfile')
  raise Thor::Error, "Can't locate a valid Gemfile at path: #{File.expand_path project_root}" unless File.exist?(gemfile)

  unless cocoapods_in_gemfile? gemfile
    say_status :add, 'Add cocoapods to the Gemfile', :blue
    File.open(gemfile, "a") { |f| f.write 'gem "Cocoapods"' } 
    run! 'bundle', :capture => true
  end
end
cocoapods_in_gemfile?(gemfile_path) click to toggle source
# File lib/fwtoolkit/cli/cocoapods.rb, line 64
def cocoapods_in_gemfile?(gemfile_path)
   File.read(gemfile_path).split("\n").select{ |line| line =~ /gem .Cocoapods./ }.count == 0
end
install_cocoapods_gem() click to toggle source
# File lib/fwtoolkit/cli/cocoapods.rb, line 31
def install_cocoapods_gem
  if inside(ENV['HOME']) {Gem::gem_available? 'cocoapods'}
    say_status :skip, 'Cocoapods is already installed', :blue
  else
     say_status :install, 'Installing cocoapods gem system-wise (requires root password)', :green
     run! 'sudo gem install cocoapods', {:capture => true}
  end
end
setup_cocoapods_repos() click to toggle source
# File lib/fwtoolkit/cli/cocoapods.rb, line 40
def setup_cocoapods_repos
  # I'm avoiding calling cocoapods directly in order not to need them as a dependecy for this set of commands
  say_status :warning, 'Cocoapods doesn\'t seem to be installed in your system. Please run fwt pods setup', :yellow if !Gem::gem_available?('cocoapods')
  fw_repo_path = File.join(ENV['CP_REPOS_DIR'] || "~/.cocoapods", 'fw')
  if Dir.exists? fw_repo_path
    say_status :skip, 'FW\'s podspec repository already installed', :blue
  else
    say_status :configure, 'Configuring FW\'s podspec repository', :green
    FileUtils.mkdir_p fw_repo_path
    inside(fw_repo_path) { run! 'git clone git@github.com:FutureWorkshops/FWTPodspecs.git .', :capture => true }
  end
end