Class: KZ::KZSwiftAttachOCFeature

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-kz/helpers/repair_dynamic_swift.rb

Instance Method Summary collapse

Constructor Details

#initializeKZSwiftAttachOCFeature

Returns a new instance of KZSwiftAttachOCFeature.



325
326
327
328
# File 'lib/cocoapods-kz/helpers/repair_dynamic_swift.rb', line 325

def initialize
  @all_kz_pod_targets = KZ::KZGlobalHelper.instance.kz_analyzer.all_kz_pod_targets
  @specify_pod_names = KZ::KZGlobalHelper.instance.specify_pod_names
end

Instance Method Details

#repairObject



330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/cocoapods-kz/helpers/repair_dynamic_swift.rb', line 330

def repair
  @all_kz_pod_targets.values.each do |kz_pod_target|
    next unless kz_pod_target.is_dev_pod
    next if @specify_pod_names.count > 0 && !@specify_pod_names.include?(kz_pod_target.name)

    need_repair_files = []
    kz_pod_target.native_pod_target.file_accessors.each do |file_accessor|
      next if file_accessor.spec.test_specification

      file_accessor.origin_source_files.each do |source_file|
        if source_file.extname == ".swift"
          need_repair_files << source_file
        end
      end
    end

    puts "Start reair '#{kz_pod_target.name}' swfit files..."
    need_repair_files.each do |swift_file_path|
      swift_file = File.open(swift_file_path, 'r')
      swift_files = swift_file.readlines
      swift_file.close
      swift_types = KZSwiftFileAnalyse.analyse_swift_file(swift_files, false)

      new_swift_contexts = []
      swift_types.each do |swift_type|
        new_swift_contexts.concat(swift_type.get_oc_feature_contexts())
      end
      # puts new_swift_contexts
      write_swift_file(swift_file_path, new_swift_contexts)
    end
  end

end

#write_swift_file(file_path, contexts) ⇒ Object



364
365
366
367
368
369
370
# File 'lib/cocoapods-kz/helpers/repair_dynamic_swift.rb', line 364

def write_swift_file(file_path, contexts)
  swift_file = File.open(file_path, 'w')
  contexts.each do |new_line|
    swift_file.write(new_line)
  end
  swift_file.close
end