Class: Protobuf::Visitor::Base
- Inherits:
-
Object
- Object
- Protobuf::Visitor::Base
- Defined in:
- lib/protobuf/compiler/visitors.rb
Direct Known Subclasses
CreateDescriptorVisitor, CreateMessageVisitor, CreateRpcVisitor
Instance Attribute Summary collapse
-
#silent ⇒ Object
readonly
Returns the value of attribute silent.
Instance Method Summary collapse
- #create_file_with_backup(filename, contents, executable = false) ⇒ Object
- #log_writing(filename, message = "writing...") ⇒ Object
Instance Attribute Details
#silent ⇒ Object (readonly)
Returns the value of attribute silent.
9 10 11 |
# File 'lib/protobuf/compiler/visitors.rb', line 9 def silent @silent end |
Instance Method Details
#create_file_with_backup(filename, contents, executable = false) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/protobuf/compiler/visitors.rb', line 11 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
31 32 33 |
# File 'lib/protobuf/compiler/visitors.rb', line 31 def log_writing(filename, ="writing...") puts "#{filename} #{}" unless silent end |