Class: Pod::Command::Spec::Create

Inherits:
Pod::Command::Spec show all
Defined in:
lib/cocoapods/command/spec.rb

Overview

———————————————————————–#

Instance Method Summary collapse

Methods inherited from Pod::Command

options, parse, report_error, run

Methods included from Pod::Config::Mixin

#config

Constructor Details

#initialize(argv) ⇒ Create

Returns a new instance of Create.



23
24
25
26
# File 'lib/cocoapods/command/spec.rb', line 23

def initialize(argv)
  @name_or_url, @url = argv.shift_argument, argv.shift_argument
  super
end

Instance Method Details

#runObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cocoapods/command/spec.rb', line 33

def run
  if repo_id_match = (@url || @name_or_url).match(/github.com\/([^\/\.]*\/[^\/\.]*)\.*/)
    # This is to make sure Faraday doesn't warn the user about the `system_timer` gem missing.
    old_warn, $-w = $-w, nil
    begin
      require 'faraday'
    ensure
      $-w = old_warn
    end
    require 'octokit'

    repo_id = repo_id_match[1]
    data = github_data_for_template(repo_id)
    data[:name] = @name_or_url if @url
    UI.puts semantic_versioning_notice(repo_id, data[:name]) if data[:version] == '0.0.1'
  else
    data = default_data_for_template(@name_or_url)
  end
  spec = spec_template(data)
  (Pathname.pwd + "#{data[:name]}.podspec").open('w') { |f| f << spec }
  UI.puts "\nSpecification created at #{data[:name]}.podspec".green
end

#validate!Object



28
29
30
31
# File 'lib/cocoapods/command/spec.rb', line 28

def validate!
  super
  help! "A pod name or repo URL is required." unless @name_or_url
end