Class: Pod::Command::Lib::Create

Inherits:
Pod::Command::Lib show all
Extended by:
Executable
Defined in:
lib/cocoapods/command/lib/create.rb

Constant Summary collapse

TEMPLATE_REPO =
'https://github.com/CocoaPods/pod-template.git'.freeze
TEMPLATE_INFO_URL =
'https://github.com/CocoaPods/pod-template'.freeze
CREATE_NEW_POD_INFO_URL =
'https://guides.cocoapods.org/making/making-a-cocoapod'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Executable

capture_command, capture_command!, executable, execute_command, popen3, reader, which, which!

Methods inherited from Pod::Command

#ensure_master_spec_repo_exists!, ensure_not_root_or_allowed!, git_version, #installer_for_config, report_error, run, #verify_lockfile_exists!, verify_minimum_git_version!, #verify_podfile_exists!, verify_xcode_license_approved!

Methods included from Pod::Config::Mixin

#config

Constructor Details

#initialize(argv) ⇒ Create

Returns a new instance of Create.



24
25
26
27
28
29
# File 'lib/cocoapods/command/lib/create.rb', line 24

def initialize(argv)
  @name = argv.shift_argument
  @template_url = argv.option('template-url', TEMPLATE_REPO)
  super
  @additional_args = argv.remainder!
end

Class Method Details

.optionsObject



18
19
20
21
22
# File 'lib/cocoapods/command/lib/create.rb', line 18

def self.options
  [
    ['--template-url=URL', 'The URL of the git repo containing a compatible template'],
  ].concat(super)
end

Instance Method Details

#clone_templatevoid (private)

This method returns an undefined value.

Clones the template from the remote in the working directory using the name of the Pod.



63
64
65
66
67
# File 'lib/cocoapods/command/lib/create.rb', line 63

def clone_template
  UI.section("Cloning `#{template_repo_url}` into `#{@name}`.") do
    git! ['clone', template_repo_url, @name]
  end
end

#configure_templatevoid (private)

This method returns an undefined value.

Runs the template configuration utilities.



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cocoapods/command/lib/create.rb', line 73

def configure_template
  UI.section("Configuring #{@name} template.") do
    Dir.chdir(@name) do
      if File.exist?('configure')
        system({ 'COCOAPODS_VERSION' => Pod::VERSION }, './configure', @name, *@additional_args)
      else
        UI.warn 'Template does not have a configure file.'
      end
    end
  end
end

This method returns an undefined value.

Runs the template configuration utilities.



89
90
91
92
# File 'lib/cocoapods/command/lib/create.rb', line 89

def print_info
  UI.puts "\nTo learn more about the template see `#{template_repo_url}`."
  UI.puts "To learn more about creating a new pod, see `#{CREATE_NEW_POD_INFO_URL}`."
end

#runObject



39
40
41
42
43
# File 'lib/cocoapods/command/lib/create.rb', line 39

def run
  clone_template
  configure_template
  print_info
end

#template_repo_urlObject (private)

Checks if a template URL is given else returns the TEMPLATE_REPO URL

Returns:

  • String



98
99
100
# File 'lib/cocoapods/command/lib/create.rb', line 98

def template_repo_url
  @template_url || TEMPLATE_REPO
end

#validate!Object



31
32
33
34
35
36
37
# File 'lib/cocoapods/command/lib/create.rb', line 31

def validate!
  super
  help! 'A name for the Pod is required.' unless @name
  help! 'The Pod name cannot contain spaces.' if @name =~ /\s/
  help! 'The Pod name cannot contain plusses.' if @name =~ /\+/
  help! "The Pod name cannot begin with a '.'" if @name[0, 1] == '.'
end