Class: TYUtil::TYFile
- Inherits:
-
Object
- Object
- TYUtil::TYFile
- Defined in:
- lib/tuya/ci/core/util/file.rb
Class Method Summary collapse
- .add_to_line(target, line_content, line_number) ⇒ Object
- .delete(path) ⇒ Object
- .folder_copy(from, to, is_need_delete = true) ⇒ Object
- .line_contain_content(target, content, lastMatch = true) ⇒ Object
-
.podspec_files(podspec) ⇒ Object
def self.copy(from, to, is_need_delete=true) if File.exist? from TYCiCore::EXE.exe(‘cp’, %W(-a #from #to)) TYCiCore::EXE.exe(‘rm’, %W(-rf #to)) if is_needend_delete end to end.
- .read(filepath) ⇒ Object
- .unzip(target, path = './') ⇒ Object
Class Method Details
.add_to_line(target, line_content, line_number) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/tuya/ci/core/util/file.rb', line 15 def self.add_to_line(target, line_content, line_number) line_number_temp = 0 target.each_line do |line| if (line_number_temp += 1) == line_number target.gsub!(/#{line}/, "#{line}#{line_content}\n") end end target end |
.delete(path) ⇒ Object
7 8 9 |
# File 'lib/tuya/ci/core/util/file.rb', line 7 def self.delete(path) `rm #{path}` end |
.folder_copy(from, to, is_need_delete = true) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tuya/ci/core/util/file.rb', line 38 def self.folder_copy(from, to, is_need_delete=true ) target = to + '/' << from.split('/')[-1] if is_need_delete TYCiCore::EXE.exe('rm', %W(-rf #{to})) if File.exist? target else raise 'File to copy at is exist.' end TYCiCore::EXE.exe('mkdir', %W(-p #{to})) TYCiCore::EXE.exe('cp', %W(-a #{from} #{to})) target end |
.line_contain_content(target, content, lastMatch = true) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tuya/ci/core/util/file.rb', line 25 def self.line_contain_content(target, content, lastMatch=true) line_number = 0 exist_num = 0 if !(content.nil? || content.empty?) target.each_line do |line| line_number += 1 exist_num = line_number if line.include?(content) break unless lastMatch end end exist_num end |
.podspec_files(podspec) ⇒ Object
def self.copy(from, to, is_need_delete=true) if File.exist? from TYCiCore::EXE.exe(‘cp’, %W(-a #from #to)) TYCiCore::EXE.exe(‘rm’, %W(-rf #to)) if is_needend_delete end to end
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tuya/ci/core/util/file.rb', line 63 def self.podspec_files(podspec) if podspec path = Pathname(podspec) raise Informative, "Couldn't find #{podspec}" unless path.exist? [path] else files = Pathname.glob('*.podspec{,.json}') # raise Informative, "Couldn't find any podspec files in current directory" if files.empty? puts "Couldn't find any podspec files in current directory".red if files.empty? files end end |
.read(filepath) ⇒ Object
11 12 13 |
# File 'lib/tuya/ci/core/util/file.rb', line 11 def self.read(filepath) end |
.unzip(target, path = './') ⇒ Object
3 4 5 |
# File 'lib/tuya/ci/core/util/file.rb', line 3 def self.unzip(target, path='./') `unzip #{target} -d #{path}` end |