Sha256: b0e0fc0425f9e4d51489c83c437eab60cdd4de1d89d64712a07d2f914c4d5511

Contents?: true

Size: 775 Bytes

Versions: 5

Compression:

Stored size: 775 Bytes

Contents

puts __FILE__ if defined?(DEBUG)

class Text
  def self.replace_in_glob(glob,search,replace)
     Dir.glob(glob).each{ |f| replace_in_file(f,search,replace) }
  end
   
  def self.replace_in_file(filename,search,replace)
    text1 = IO.read(filename)
    text2 = text1.gsub(search) { |str| str=replace }
    unless text1==text2
      File.open(filename,"w") { |f| f.puts text2 }
      return true
    end
    false
  end

 def self.copy_if_different(source,destination)
    if(!File.exists?(destination))
      FileUtils.cp source, destination
    else
      source_text=IO.read(source)
      destination_text=IO.read(destination)
      if(source_text != destination_text)
        FileUtils.rm destination
        FileUtils.cp source, destination
      end
    end
   end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dev-2.1.75 lib/base/text.rb
dev-2.1.74 lib/base/text.rb
dev-2.1.73 lib/base/text.rb
dev-2.1.72 lib/base/text.rb
dev-2.1.71 lib/base/text.rb