Class: ArchiveBuilder::FileBuilder

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/archive_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ FileBuilder

Returns a new instance of FileBuilder.



49
50
51
# File 'lib/archive_builder.rb', line 49

def initialize(filename)
  @filename = filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



48
49
50
# File 'lib/archive_builder.rb', line 48

def filename
  @filename
end

Instance Method Details

#create_dirsObject



58
59
60
61
# File 'lib/archive_builder.rb', line 58

def create_dirs
  dirname = File.dirname(filename)
  mkdir_p dirname unless File.exists?(dirname) 
end

#with(content) ⇒ Object



53
54
55
56
57
# File 'lib/archive_builder.rb', line 53

def with(content)
  create_dirs
  File.open(filename, "w+") { |f| f.puts content }
  return self
end