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

Inherits:
Pod::Command::Swordfish::Spec show all
Defined in:
lib/swordfish/command/spec/create.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pod::Command::Swordfish

#validate!

Methods included from Ocean::SpecFilesHelper

#binary_spec, #binary_spec_files, #binary_template_spec, #binary_template_spec_file, #binary_template_spec_files, #clear_binary_spec_file_if_needed, #code_spec, #code_spec_files, #create_binary_spec_file, #find_spec_file, #spec_files

Methods included from Ocean::SourcesHelper

#binary_source, #code_source, #sources_manager, #sources_option, #valid_sources

Constructor Details

#initialize(argv) ⇒ Create

Returns a new instance of Create.



26
27
28
29
30
31
32
# File 'lib/swordfish/command/spec/create.rb', line 26

def initialize(argv)
  @platforms = argv.option('platforms', 'ios')
  @allow_overwrite = argv.flag?('overwrite', true)
  @template_podspec = argv.option('template-podspec')
  @podspec = argv.shift_argument
  super
end

Class Method Details

.optionsObject



18
19
20
21
22
23
24
# File 'lib/swordfish/command/spec/create.rb', line 18

def self.options
  [
    ['--platforms=ios', '生成二进制 spec 支持的平台'],
    ['--template-podspec=A.binary-template.podspec', '生成拥有 subspec 的二进制 spec 需要的模版 podspec, 插件会更改 version 和 source'],
    ['--no-overwrite', '不允许覆盖']
  ].concat(super)
end

Instance Method Details

#runObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/swordfish/command/spec/create.rb', line 34

def run
  UI.puts "开始读取 podspec 文件...\n"

  code_spec = Pod::Specification.from_file(spec_file)
  if template_spec_file
    template_spec = Pod::Specification.from_file(template_spec_file)
  end

  if binary_spec && !@allow_overwrite
    UI.warn "二进制 podspec 文件 #{binary_spec_files.first} 已存在.\n"
  else
    UI.puts "开始生成二进制 podspec 文件...\n"
    spec_file = create_binary_spec_file(code_spec, template_spec)
    UI.puts "创建二进制 podspec 文件 #{spec_file} 成功.\n".green
  end
end

#spec_fileObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/swordfish/command/spec/create.rb', line 61

def spec_file
  @spec_file ||= begin
    if @podspec
      find_spec_file(@podspec)
    else
      if code_spec_files.empty?
        raise Informative, '当前目录下没有找到可用源码 podspec.'
      end

      code_spec_files.first
    end
  end
end

#template_spec_fileObject



51
52
53
54
55
56
57
58
59
# File 'lib/swordfish/command/spec/create.rb', line 51

def template_spec_file
  @template_spec_file ||= begin
    if @template_podspec
      find_spec_file(@template_podspec)
    else
      binary_template_spec_file
    end
  end
end