Class: Protobuf::Visitor::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/protobuf/compiler/visitors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#silentObject (readonly)

Returns the value of attribute silent.



8
9
10
# File 'lib/protobuf/compiler/visitors.rb', line 8

def silent
  @silent
end

Instance Method Details

#create_file_with_backup(filename, contents, executable = false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/protobuf/compiler/visitors.rb', line 10

def create_file_with_backup(filename, contents, executable=false)
  if File.exist? filename
    if File.read(filename) == contents
      # do nothing
      return
    else
      backup_filename = "#{filename}.#{Time.now.to_i}" 
      log_writing "#{backup_filename}", "backingup..."
      FileUtils.copy filename, backup_filename
    end
  end

  File.open(filename, 'w') do |file| 
    log_writing filename
    FileUtils.mkpath File.dirname(filename)
    file.write contents
  end
  FileUtils.chmod 0755, filename if executable
end

#log_writing(filename, message = "writing...") ⇒ Object



30
31
32
# File 'lib/protobuf/compiler/visitors.rb', line 30

def log_writing(filename, message="writing...")
  puts "#{filename} #{message}" unless silent
end