Commit d382eb07 authored by Ian Ynda-Hummel's avatar Ian Ynda-Hummel

Address line note comments on code style.

parent 7c334329
require 'xcodeproj' require 'xcodeproj'
require 'active_support/core_ext/string/strip'
module Pod module Pod
class Command class Command
...@@ -22,7 +23,7 @@ module Pod ...@@ -22,7 +23,7 @@ module Pod
def validate! def validate!
super super
help! "Existing Podfile found in directory" if File.file? @podfile_path help! "Existing Podfile found in directory" unless config.podfile.nil?
unless @project_path unless @project_path
help! "No xcode project found, please specify one" unless @project_paths.length > 0 help! "No xcode project found, please specify one" unless @project_paths.length > 0
help! "Multiple xcode projects found, please specify one" unless @project_paths.length == 1 help! "Multiple xcode projects found, please specify one" unless @project_paths.length == 1
...@@ -36,33 +37,36 @@ module Pod ...@@ -36,33 +37,36 @@ module Pod
@podfile_path.open('w') { |f| f << podfile_template(@xcode_project) } @podfile_path.open('w') { |f| f << podfile_template(@xcode_project) }
end end
private
# @param [Xcodeproj::Project] project
# The xcode project to generate a podfile for.
#
# @return [String] the text of the Podfile for the provided project
#
def podfile_template(project) def podfile_template(project)
platforms = project.targets.map { |t| t.platform_name }.uniq podfile = <<-PLATFORM.strip_heredoc
has_global_platform = platforms.length == 1 # Uncomment this line to define a global platform for your project
if has_global_platform # platform :ios, "6.0"
podfile = <<-PLATFORM PLATFORM
platform :#{platforms.first}
PLATFORM
else
podfile = <<-PLATFORM
# Uncomment this line to define a global platform for your project
# platform :ios, "6.0"
PLATFORM
end
for target in project.targets for target in project.targets
podfile << target_module(target, !has_global_platform) podfile << target_module(target, !has_global_platform)
end end
podfile podfile
end end
def target_module(target, define_platform = true) # @param [Xcodeproj::PBXTarget] target
platform = "platform :#{target.platform_name}" if define_platform # A target to generate a Podfile target module for.
return <<-TARGET #
# @return [String] the text for the target module
#
def target_module(target)
return <<-TARGET.strip_heredoc
target "#{target.name}" do target "#{target.name}" do
#{platform}
end end
TARGET TARGET
end end
end end
end end
......
...@@ -26,6 +26,17 @@ module Pod ...@@ -26,6 +26,17 @@ module Pod
Dir.chdir(pwd) Dir.chdir(pwd)
end end
it "complains if a Podfile already exists" do
pwd = Dir.pwd
Dir.chdir(temporary_directory)
(Pathname.pwd + 'Podfile').open('w') { |f| f << "pod 'AFNetworking'" }
Xcodeproj::Project.new.save_as(temporary_directory + 'test1.xcodeproj')
lambda { run_command('init') }.should.raise CLAide::Help
Dir.chdir(pwd)
end
it "creates a Podfile for a project in current directory" do it "creates a Podfile for a project in current directory" do
pwd = Dir.pwd pwd = Dir.pwd
Dir.chdir(temporary_directory) Dir.chdir(temporary_directory)
...@@ -45,6 +56,7 @@ module Pod ...@@ -45,6 +56,7 @@ module Pod
Xcodeproj::Project.new.save_as(temporary_directory + 'test2.xcodeproj') Xcodeproj::Project.new.save_as(temporary_directory + 'test2.xcodeproj')
run_command('init', 'test2.xcodeproj') run_command('init', 'test2.xcodeproj')
Pathname.new(temporary_directory + 'Podfile').exist?.should == true Pathname.new(temporary_directory + 'Podfile').exist?.should == true
config.podfile.nil?.should == false
Dir.chdir(pwd) Dir.chdir(pwd)
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment