Class: Ocean::SpecificationSource::Creator

Inherits:
Object
  • Object
show all
Defined in:
lib/swordfish/helpers/spec_source_creator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Creator.



12
13
14
15
16
# File 'lib/swordfish/helpers/spec_source_creator.rb', line 12

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

Instance Attribute Details

#code_specObject (readonly)

Returns the value of attribute code_spec.



9
10
11
# File 'lib/swordfish/helpers/spec_source_creator.rb', line 9

def code_spec
  @code_spec
end

#specObject (readonly)

Returns the value of attribute spec.



10
11
12
# File 'lib/swordfish/helpers/spec_source_creator.rb', line 10

def spec
  @spec
end

Instance Method Details

#clear_spec_fileObject



46
47
48
# File 'lib/swordfish/helpers/spec_source_creator.rb', line 46

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

#create(is_framework) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/swordfish/helpers/spec_source_creator.rb', line 22

def create(is_framework)
  # spec = nil
  if is_framework
    spec = create_framework_from_code_spec
  else
    spec = create_from_code_spec
  end

  spec
end

#filenameObject



50
51
52
# File 'lib/swordfish/helpers/spec_source_creator.rb', line 50

def filename
  @filename ||= "#{Ocean::Config::Builder.instance.binary_json_dir_name}/#{spec.name}.binary.podspec.json"
end

#validate!Object

Raises:

  • (Pod::Informative)


18
19
20
# File 'lib/swordfish/helpers/spec_source_creator.rb', line 18

def validate!
  raise Pod::Informative, '源码 podspec 不能为空 .' unless code_spec
end

#write_spec_file(file = filename) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/swordfish/helpers/spec_source_creator.rb', line 33

def write_spec_file(file = filename)

  FileUtils.mkdir_p(Ocean::Config::Builder.instance.binary_json_dir) unless File.exist?(Ocean::Config::Builder.instance.binary_json_dir)
  FileUtils.rm_rf(file) if File.exist?(file)

  File.open(file, 'w+') do |f|
    # f.write("# MARK: converted automatically by plugin cocoapods-swordfish @slj \r\n")
    f.write(spec.to_pretty_json)
  end

  @filename = file
end