class TYCiCore::PodSpec
Attributes
content[RW]
file[RW]
Public Class Methods
new(podspec)
click to toggle source
# File lib/tuya/ci/core/podspec.rb, line 10 def initialize(podspec) puts "Tuya podspec is #{podspec}".green raise 'podspec cannot be nil' unless podspec @podspec_json = podspec_json? podspec @file = TYUtil::TYFile.podspec_files(podspec)[0] @content = File.read(@file) end
Public Instance Methods
podspec_json?(podspec)
click to toggle source
# File lib/tuya/ci/core/podspec.rb, line 70 def podspec_json?(podspec) podspec.scan(/podspec.json$/).size > 0 end
save()
click to toggle source
# File lib/tuya/ci/core/podspec.rb, line 63 def save puts "Podspec: #{@file} saved".green fh = File.new(@file, "w") fh.puts @content fh.close end
update(key, value)
click to toggle source
# File lib/tuya/ci/core/podspec.rb, line 35 def update(key, value) unless @podspec_json puts "Podspec: #{@file} update key: #{key} value: #{value}".green res = @content.scan(/.#{key}\s*=\s*'#{value}'/) need_update = res.size == 0 if need_update @content.gsub!(/s.#{key}\s*=(.*?)'$/, "s.#{key} = '#{value}'") end need_update end end
update_add(key, value, output=true)
click to toggle source
# File lib/tuya/ci/core/podspec.rb, line 48 def update_add(key, value, output=true) unless @podspec_json puts "Podspec: #{@file} update_add key: #{key} value: #{value}".green if output res = @content.scan(/.#{key}\s*=\s*/) key_is_exist = res.size == 0 puts key_is_exist if key_is_exist @content = TYUtil::TYFile.add_to_line @content, value, 8 else @content.gsub!(/s.#{key}\s*=(.*?)'$/, "s.#{key} = #{value}") end key_is_exist end end
value_key(key)
click to toggle source
# File lib/tuya/ci/core/podspec.rb, line 21 def value_key(key) if @podspec_json content_json = JSON @content else content_temp = TYCiCore::EXE.exe 'pod', %W(ipc spec #{@file}), true content_temp = content_temp.match(/^\{.*\}$/m)[0] puts content_temp content_json = JSON content_temp end eval("content_json" << key.split('/').map { |i| "[\"" + i + "\"]" }.join) if content_json end