Class: Pod::SpecBuilder
- Inherits:
-
Object
- Object
- Pod::SpecBuilder
- Defined in:
- lib/cocoapods-packager/spec_builder.rb
Instance Method Summary collapse
- #framework_path ⇒ Object
- #get_all_dependenices(plat) ⇒ Object
- #get_all_type(type) ⇒ Object
- #get_platform ⇒ Object
- #get_resource ⇒ Object
- #get_spec_json ⇒ Object
-
#initialize(spec, source, embedded, dynamic) ⇒ SpecBuilder
constructor
A new instance of SpecBuilder.
- #process_platform_hash ⇒ Object
- #spec_close ⇒ Object
- #spec_metadata ⇒ Object
- #spec_platform(platform) ⇒ Object
- #subspec_json ⇒ Object
Constructor Details
#initialize(spec, source, embedded, dynamic) ⇒ SpecBuilder
Returns a new instance of SpecBuilder.
4 5 6 7 8 9 10 11 12 |
# File 'lib/cocoapods-packager/spec_builder.rb', line 4 def initialize(spec, source, , dynamic) @spec = spec name = spec.attributes_hash['name'] version = spec.attributes_hash['version'] @source = source.nil? ? "{ :http => 'https://10.0.0.0/staticpods/#{name}/#{name}-#{version}.zip' }" : source @embedded = @dynamic = dynamic @platform = nil end |
Instance Method Details
#framework_path ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/cocoapods-packager/spec_builder.rb', line 14 def framework_path if @embedded @spec.name + '.embeddedframework' + '/' + @spec.name + '.framework' else @spec.name + '.framework' end end |
#get_all_dependenices(plat) ⇒ Object
148 149 150 151 152 153 |
# File 'lib/cocoapods-packager/spec_builder.rb', line 148 def get_all_dependenices(plat) depen = @spec.all_dependencies(plat) depen = depen.map {|den| den.name} depen = depen.select {|de| !de.include?('/')} depen end |
#get_all_type(type) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 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 107 108 109 110 111 112 |
# File 'lib/cocoapods-packager/spec_builder.rb', line 50 def get_all_type(type) subspecs = subspec_json all_frame = Set.new if subspecs.length > 0 subspecs.each do |subspec| subspec = JSON.parse(subspec) if !subspec next end df = subspec[type] if df if df.class == String all_frame.add(df) elsif df.class == Array all_frame.merge(df) end end plat = subspec['ios'] if plat if plat.class == Hash plat_f = plat[type] if plat_f if plat_f.class == String all_frame.add(plat_f) elsif plat_f.class == Array all_frame.merge(plat_f) end end end end end end spec_json = JSON.parse(get_spec_json) dfm = spec_json[type] if dfm if dfm.class == String all_frame.add(dfm) elsif dfm.class == Array all_frame.merge(dfm) end end if !dfm return all_frame end if dfm.class != Hash return all_frame end plat = dfm['ios'] if plat if plat.class == Hash plat_f = plat[type] if plat_f if plat_f.class == String all_frame.add(plat_f) elsif plat_f.class == Array all_frame.merge(plat_f) end end end end # puts "get all type --> #{type} value --> #{all_frame}" return all_frame end |
#get_platform ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/cocoapods-packager/spec_builder.rb', line 136 def get_platform platform_str = '' platform = process_platform_hash if platform if platform['ios'] platform_str = " s.platform = :ios, '#{platform['ios']}' \n" else platform_str = " s.platform = :ios" end end platform_str end |
#get_resource ⇒ Object
116 117 118 |
# File 'lib/cocoapods-packager/spec_builder.rb', line 116 def get_resource return get_spec_json.include?('resource_bundles') || get_spec_json.include?('resource') || get_spec_json.include?('resources') || get_spec_json.include?('resource_bundle') end |
#get_spec_json ⇒ Object
113 114 115 |
# File 'lib/cocoapods-packager/spec_builder.rb', line 113 def get_spec_json return @spec.to_pretty_json end |
#process_platform_hash ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/cocoapods-packager/spec_builder.rb', line 119 def process_platform_hash case value = @spec.attributes_hash['platforms'] when String { value => nil } when Array result = {} value.each do |a_value| result[a_value] = nil end result when Hash value else {} end end |
#spec_close ⇒ Object
202 203 204 |
# File 'lib/cocoapods-packager/spec_builder.rb', line 202 def spec_close "end\n" end |
#spec_metadata ⇒ Object
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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/cocoapods-packager/spec_builder.rb', line 154 def spec = spec_header spec += get_platform frames = get_all_type('frameworks') if frames.length > 0 spec += ' s.frameworks = ' frames.each do |val| spec += "'#{val}'," end spec = spec.delete_suffix(',') spec += "\n" end framework = get_all_type('framework') if framework.length > 0 framework.each do |val| spec += " s.framework = #{val}\n" end end libs = get_all_type('libraries') if libs.length > 0 spec += " s.libraries = " libs.each do |val| spec += "'#{val}'," end spec = spec.delete_suffix(',') spec += "\n" end library = get_all_type('library') if library.length > 0 library.each do |val| spec += " s.library = #{val} \n" end end dependices = get_all_dependenices(@platform) if dependices.length > 0 dependices.each do |val| spec += " s.dependency '#{val}' \n" end spec += "\n" end res = get_resource if res spec += " s.resources = 'ios/#{framework_path}/Resources/#{@spec.name}.bundle' \n" end spec end |
#spec_platform(platform) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cocoapods-packager/spec_builder.rb', line 22 def spec_platform(platform) fwk_base = platform.name.to_s + '/' + framework_path spec = <<RB s.#{platform.name}.deployment_target = '#{platform.deployment_target}' s.#{platform.name}.vendored_framework = '#{fwk_base}' RB %w(requires_arc xcconfig).each do |attribute| attributes_hash = @spec.attributes_hash[platform.name.to_s] next if attributes_hash.nil? value = attributes_hash[attribute] next if value.nil? value = "'#{value}'" if value.class == String spec += " s.#{platform.name}.#{attribute} = #{value}\n" end @platform = platform spec end |
#subspec_json ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/cocoapods-packager/spec_builder.rb', line 42 def subspec_json if @spec.subspecs.length < 1 return [] end new_sub = @spec.subspecs.map {|spec| spec.to_pretty_json} return new_sub end |