Class: CBin::Specification::Creator

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-tdf-bin/helpers/spec_creator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code_spec, template_spec, platforms = 'ios') ⇒ Creator

Returns a new instance of Creator.



11
12
13
14
15
16
# File 'lib/cocoapods-tdf-bin/helpers/spec_creator.rb', line 11

def initialize(code_spec, template_spec, platforms = 'ios')
  @code_spec = code_spec
  @template_spec = template_spec
  @platforms = Array(platforms)
  validate!
end

Instance Attribute Details

#code_specObject (readonly)

Returns the value of attribute code_spec.



7
8
9
# File 'lib/cocoapods-tdf-bin/helpers/spec_creator.rb', line 7

def code_spec
  @code_spec
end

#specObject (readonly)

Returns the value of attribute spec.



9
10
11
# File 'lib/cocoapods-tdf-bin/helpers/spec_creator.rb', line 9

def spec
  @spec
end

#template_specObject (readonly)

Returns the value of attribute template_spec.



8
9
10
# File 'lib/cocoapods-tdf-bin/helpers/spec_creator.rb', line 8

def template_spec
  @template_spec
end

Instance Method Details

#clear_spec_fileObject



46
47
48
# File 'lib/cocoapods-tdf-bin/helpers/spec_creator.rb', line 46

def clear_spec_file
  File.delete(filename) if File.exist?(filename)
end

#createObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/cocoapods-tdf-bin/helpers/spec_creator.rb', line 25

def create
  spec = template_spec ? create_from_code_spec_and_template_spec : create_from_code_spec

  Pod::UI.message '生成二进制 podspec 内容: '
  spec.to_pretty_json.split("\n").each do |text|
    Pod::UI.message text
  end

  spec
end

#filenameObject



50
51
52
# File 'lib/cocoapods-tdf-bin/helpers/spec_creator.rb', line 50

def filename
  @filename ||= "#{spec.name}.podspec.json"
end

#validate!Object

Raises:

  • (Pod::Informative)


18
19
20
21
22
23
# File 'lib/cocoapods-tdf-bin/helpers/spec_creator.rb', line 18

def validate!
  raise Pod::Informative, '源码 podspec 不能为空 .' unless code_spec
  if code_spec.subspecs.any? && template_spec.nil?
    raise Pod::Informative, "不支持自动生成存在 subspec 的二进制 podspec , 需要提供模版文件 #{code_spec.name}.binary.podspec.template ."
  end
end

#write_spec_file(file = filename) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/cocoapods-tdf-bin/helpers/spec_creator.rb', line 36

def write_spec_file(file = filename)
  create unless spec

  File.open(file, 'w+') do |f|
    f.write(spec.to_pretty_json)
  end

  @filename = file
end