Module: Buildable::FileMaker
- Defined in:
- lib/buildable/file_maker.rb
Class Method Summary collapse
-
.plain_text(filename, options = {}) ⇒ Object
create plain_text file with content.
- .template(name, location = './', options = {}) ⇒ Object
Class Method Details
.plain_text(filename, options = {}) ⇒ Object
create plain_text file with content
plain_text(‘test.txt’) { |content| content << “hi” } # => create test.txt file with “hi” inside
10 11 12 13 14 |
# File 'lib/buildable/file_maker.rb', line 10 def plain_text(filename, = {}) # check if exist and be overwrite content = yield('') File.open(filename, 'w') { |file| file.write content } end |
.template(name, location = './', options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/buildable/file_maker.rb', line 16 def template(name, location = './', = {}) destination = File.join(location, name) # check if exist and can overwrite template = load_template(name) raise "Template #{name} not found" unless template builder = ERB.new(template) File.open(destination, 'w') { |f| f.write builder.result } end |