Class: Xcodeproj::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/podfileDep/check/util.rb

Class Method Summary collapse

Class Method Details

.get_podspec_content(podspec_path) ⇒ Hash

读取podspec内容

Parameters:

  • podspec_path:: (Pathname)

Returns:

  • (Hash)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/podfileDep/check/util.rb', line 6

def self.get_podspec_content(podspec_path)

  podspec_json_path = podspec_path.to_s.end_with?(".podspec.json") ? podspec_path : nil

  podspec_content = nil
  if podspec_json_path and File.exist?(podspec_json_path)
    json = File.read(podspec_json_path)
    podspec_content = JSON.parse(json)
  elsif podspec_path and File.exist?(podspec_path)
    json = get_podspec_file_content(podspec_path)
    podspec_content = JSON.parse(json)
  end
  podspec_content
end

.get_podspec_file_content(podspec_path) ⇒ Object

根据podspec路径把podspec转为json



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/podfileDep/check/util.rb', line 23

def self.get_podspec_file_content(podspec_path)

  spec_contents = File.open(podspec_path, 'r:utf-8', &:read)

  if spec_contents.respond_to?(:encoding) && spec_contents.encoding.name != 'UTF-8'
    spec_contents.encode!('UTF-8')
  end

  path = Pathname.new(podspec_path)

  spec = ::Pod._eval_podspec(spec_contents, path)

  spec.to_json
end