Class: LgPodPlugin::PodSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/lg_pod_plugin/config/podspec.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ PodSpec

Returns a new instance of PodSpec.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/lg_pod_plugin/config/podspec.rb', line 63

def initialize(spec)
  if spec == nil
    @spec = nil
    @json_files = Hash.new
    @source_files = Hash.new
    return
  end
  set = Set[]
  @spec = spec
  attributes_hash = spec.send(:attributes_hash)
  return unless attributes_hash.is_a?(Hash)
  license = attributes_hash["license"]
  if license.is_a?(Hash)
    license_file = license["file"]
    set.add(license_file) if license_file
  else
    set.add("LICENSE")
  end
  # 解析主模块依赖信息
  set.merge(parse_subspec_with(attributes_hash))
  subspecs = spec.subspecs
  unless subspecs.is_a?(Array)
    self.source_files = parse_with_set set
    if self.source_files.has_key?("*")
      self.source_files.delete("*")
      self.source_files["All"] = "All"
    end
    self.json_files = spec.to_pretty_json
    return
  end
  subspecs.each do |sub_spec|
    sub_attributes_hash = sub_spec.send(:attributes_hash)
    next unless sub_attributes_hash && sub_attributes_hash.is_a?(Hash)
    sub_set = self.parse_subspec_with(sub_attributes_hash)
    next if sub_set.empty?
    set.merge(sub_set)
  end
  self.source_files = parse_with_set set
  if self.source_files.has_key?("*")
    self.source_files.delete("*")
    self.source_files["All"] = "All"
  end
  self.json_files = spec.to_pretty_json
end

Instance Attribute Details

#json_filesObject

Returns the value of attribute json_files.



8
9
10
# File 'lib/lg_pod_plugin/config/podspec.rb', line 8

def json_files
  @json_files
end

#source_filesObject

Returns the value of attribute source_files.



9
10
11
# File 'lib/lg_pod_plugin/config/podspec.rb', line 9

def source_files
  @source_files
end

#specObject (readonly)

Returns the value of attribute spec.



7
8
9
# File 'lib/lg_pod_plugin/config/podspec.rb', line 7

def spec
  @spec
end

Class Method Details

.form_file(path) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/lg_pod_plugin/config/podspec.rb', line 12

def self.form_file(path)
  begin
    spec = Pod::Specification.from_file(path)
    return PodSpec.new(spec)
  rescue
    return nil
  end
end

.form_json(object) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/lg_pod_plugin/config/podspec.rb', line 54

def self.form_json(object)
  begin
    spec = Pod::Specification.from_json(object)
    return PodSpec.new(spec)
  rescue
    return nil
  end
end

.form_pod_spec(spec) ⇒ Object



50
51
52
# File 'lib/lg_pod_plugin/config/podspec.rb', line 50

def self.form_pod_spec(spec)
  return PodSpec.new(spec)
end

.form_string(string, path) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/lg_pod_plugin/config/podspec.rb', line 37

def self.form_string(string, path)
  begin
    #Work around for Rubinius incomplete encoding in 1.9 mode
    if string.respond_to?(:encoding) && string.encoding.name != 'UTF-8'
      string = string.force_encoding("gb2312").force_encoding("utf-8")
    end
    spec = Pod::Specification.from_string string, path
    return PodSpec.new(spec)
  rescue
    return nil
  end
end

Instance Method Details

#parse_module_map(source_files) ⇒ Object

解析 module_map



260
261
262
# File 'lib/lg_pod_plugin/config/podspec.rb', line 260

def parse_module_map(source_files)
  self.parse_public_source_files(source_files)
end

#parse_preserve_path(source_files) ⇒ Object

解析 parse_preserve_path



255
256
257
# File 'lib/lg_pod_plugin/config/podspec.rb', line 255

def parse_preserve_path(source_files)
  self.parse_public_source_files(source_files)
end

#parse_private_header_files(source_files) ⇒ Object

解析 private_header_files



240
241
242
# File 'lib/lg_pod_plugin/config/podspec.rb', line 240

def parse_private_header_files(source_files)
  self.parse_public_source_files(source_files)
end

#parse_project_header_files(source_files) ⇒ Object

解析 project_header_files



235
236
237
# File 'lib/lg_pod_plugin/config/podspec.rb', line 235

def parse_project_header_files(source_files)
  self.parse_public_source_files(source_files)
end

#parse_public_header_files(source_files) ⇒ Object

解析public_header_files字段的值



225
226
227
# File 'lib/lg_pod_plugin/config/podspec.rb', line 225

def parse_public_header_files(source_files)
  self.parse_public_source_files(source_files)
end

#parse_public_source_files(source_files) ⇒ Object

公共解析文件路径的方法



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/lg_pod_plugin/config/podspec.rb', line 189

def parse_public_source_files(source_files)
  return Array.new unless source_files
  array = Array.new
  if LUtils.is_a_string?(source_files)
    array.append(source_files) unless source_files.empty?
  elsif source_files.is_a?(Array)
    source_files.each do |element|
      next unless LUtils.is_a_string?(element)
      array.append(element) unless element.empty?
    end
  elsif source_files.is_a?(Hash)
    source_files.each do |_, val|
      if LUtils.is_a_string?(val)
        array.append(val) unless val.empty?
      elsif val.is_a?(Array)
        val.each do |element|
          next unless LUtils.is_a_string?(element)
          array.append(element) unless element.empty?
        end
      end
    end
  end
  array
end

#parse_resource_bundles(source_files) ⇒ Object

解析 parse_resource_bundles



230
231
232
# File 'lib/lg_pod_plugin/config/podspec.rb', line 230

def parse_resource_bundles(source_files)
  self.parse_public_source_files(source_files)
end

#parse_resource_files(source_files) ⇒ Object

解析 resource所在路径



220
221
222
# File 'lib/lg_pod_plugin/config/podspec.rb', line 220

def parse_resource_files(source_files)
  self.parse_public_source_files(source_files)
end

#parse_source_files(source_files) ⇒ Object

解析source_files路径



215
216
217
# File 'lib/lg_pod_plugin/config/podspec.rb', line 215

def parse_source_files(source_files)
  self.parse_public_source_files(source_files)
end

#parse_subspec_with(hash) ⇒ Object

公共解析解析subspec



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/lg_pod_plugin/config/podspec.rb', line 133

def parse_subspec_with(hash)
  set = Set[]
  source_files = self.parse_source_files(hash["source_files"])
  set.merge(source_files) unless source_files.empty?
  resources = self.parse_resource_files(hash["resource"] ||= hash["resources"])
  set.merge(resources) unless resources.empty?
  resource_bundles = self.parse_resource_bundles(hash["resource_bundle"] ||= hash["resource_bundles"])
  set.merge(resource_bundles) unless resource_bundles.empty?
  project_header_files = self.parse_project_header_files(hash["project_header_files"])
  set.merge(resource_bundles) unless project_header_files.empty?
  private_header_files = self.parse_private_header_files(hash["private_header_files"])
  set.merge(private_header_files) unless private_header_files.empty?
  vendored_frameworks = self.parse_vendored_frameworks(hash["vendored_frameworks"])
  set.merge(vendored_frameworks) unless vendored_frameworks.empty?
  vendored_library = self.parse_vendored_library(hash["vendored_library"] ||= hash["vendored_libraries"])
  set.merge(vendored_library) unless vendored_library.empty?
  #parse_preserve_path
  preserve_paths = self.parse_preserve_path(hash["preserve_path"] ||= hash["preserve_paths"])
  set.merge(preserve_paths) unless preserve_paths.empty?
  module_map = self.parse_module_map(hash["module_map"])
  set.merge(module_map) unless module_map.empty?
  ios_hash = hash["ios"]
  if ios_hash && ios_hash.is_a?(Hash)

    ios_source_files = self.parse_source_files(ios_hash["source_files"])
    set.merge(ios_source_files) unless ios_source_files.empty?

    ios_resources = self.parse_resource_files(ios_hash["resource"] ||= ios_hash["resources"])
    set.merge(ios_resources) unless ios_resources.empty?

    ios_resource_bundles = self.parse_resource_bundles(ios_hash["resource_bundle"] ||= ios_hash["resource_bundles"])
    set.merge(ios_resource_bundles) unless ios_resource_bundles.empty?

    ios_project_header_files = self.parse_project_header_files(ios_hash["project_header_files"])
    set.merge(ios_project_header_files) unless ios_project_header_files.empty?

    ios_private_header_files = self.parse_private_header_files(ios_hash["private_header_files"])
    set.merge(ios_private_header_files) unless ios_private_header_files.empty?

    ios_vendored_frameworks = self.parse_vendored_frameworks(ios_hash["vendored_frameworks"])
    set.merge(ios_vendored_frameworks) unless ios_vendored_frameworks.empty?

    ios_vendored_library = self.parse_vendored_library(ios_hash["vendored_library"] ||= ios_hash["vendored_libraries"])
    set.merge(ios_vendored_library) unless ios_vendored_library.empty?

    ios_preserve_paths = self.parse_preserve_path(ios_hash["preserve_path"] ||= ios_hash["preserve_paths"])
    set.merge(ios_preserve_paths) unless ios_preserve_paths.empty?

    ios_module_map = self.parse_module_map(ios_hash["module_map"])
    set.merge(ios_module_map) unless ios_module_map.empty?

  end
  set
end

#parse_vendored_frameworks(source_files) ⇒ Object

解析 vendored_frameworks



245
246
247
# File 'lib/lg_pod_plugin/config/podspec.rb', line 245

def parse_vendored_frameworks(source_files)
  self.parse_public_source_files(source_files)
end

#parse_vendored_library(source_files) ⇒ Object

解析 parse_vendored_library



250
251
252
# File 'lib/lg_pod_plugin/config/podspec.rb', line 250

def parse_vendored_library(source_files)
  self.parse_public_source_files(source_files)
end

#parse_with_set(set) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/lg_pod_plugin/config/podspec.rb', line 113

def parse_with_set(set)
  new_hash = Hash.new
  set.each do |element|
    if element.start_with?("**/")
      new_hash["All"] = "All"
    elsif element.include?("/")
      str = element.split("/", 0).first
      new_hash[str] = str unless str.empty?
    elsif element.start_with?("**.") || element.start_with?("*.")
      new_hash["All"] = "All"
    elsif element.start_with?("*.framework") || element.include?("*.a")
      new_hash["All"] = "All"
    else
      new_hash[element] = element unless element.empty?
    end
  end
  new_hash
end

#prepare_commandObject



22
23
24
25
26
27
# File 'lib/lg_pod_plugin/config/podspec.rb', line 22

def prepare_command
  json = self.to_pretty_json
  return nil unless json
  hash = JSON.parse json
  hash["prepare_command"]
end

#to_pretty_json(*a) ⇒ Object



30
31
32
33
# File 'lib/lg_pod_plugin/config/podspec.rb', line 30

def to_pretty_json(*a)
  require 'json'
  JSON.pretty_generate(self.spec.to_hash, *a) << "\n"
end

#write_to_file(path) ⇒ Object



109
110
111
# File 'lib/lg_pod_plugin/config/podspec.rb', line 109

def write_to_file(path)
  LCache.write_spec(@spec, path)
end