Class: TYCiCore::PodSpec
- Inherits:
-
Object
- Object
- TYCiCore::PodSpec
- Defined in:
- lib/tuya/ci/core/podspec.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
-
#initialize(podspec) ⇒ PodSpec
constructor
A new instance of PodSpec.
- #podspec_json?(podspec) ⇒ Boolean
- #save ⇒ Object
- #update(key, value) ⇒ Object
- #update_add(key, value, output = true) ⇒ Object
- #value_key(key) ⇒ Object
Constructor Details
#initialize(podspec) ⇒ PodSpec
Returns a new instance of PodSpec.
10 11 12 13 14 15 16 17 18 19 |
# 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 |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
8 9 10 |
# File 'lib/tuya/ci/core/podspec.rb', line 8 def content @content end |
#file ⇒ Object
Returns the value of attribute file.
7 8 9 |
# File 'lib/tuya/ci/core/podspec.rb', line 7 def file @file end |
Instance Method Details
#podspec_json?(podspec) ⇒ Boolean
70 71 72 |
# File 'lib/tuya/ci/core/podspec.rb', line 70 def podspec_json?(podspec) podspec.scan(/podspec.json$/).size > 0 end |
#save ⇒ Object
63 64 65 66 67 68 |
# 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) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# 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) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# 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) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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 |