Class: Verto::DSL::File
- Inherits:
-
Object
- Object
- Verto::DSL::File
- Defined in:
- lib/verto/dsl/file.rb
Instance Method Summary collapse
- #append(content) ⇒ Object
-
#initialize(filename, path: Verto.config.project.path) ⇒ File
constructor
A new instance of File.
- #prepend(content) ⇒ Object
- #replace(to_match, to_replace) ⇒ Object (also: #sub)
- #replace_all(to_match, to_replace) ⇒ Object (also: #gsub)
Constructor Details
Instance Method Details
#append(content) ⇒ Object
27 28 29 30 31 |
# File 'lib/verto/dsl/file.rb', line 27 def append(content) file.open('a') do |f| f << content end end |
#prepend(content) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/verto/dsl/file.rb', line 33 def prepend(content) file_content = file.read file.open('w') do |f| f << (content + file_content) end end |
#replace(to_match, to_replace) ⇒ Object Also known as: sub
11 12 13 14 15 16 17 |
# File 'lib/verto/dsl/file.rb', line 11 def replace(to_match, to_replace) content = file.read file.open('w') do |f| f << content.sub(to_match, to_replace) end end |
#replace_all(to_match, to_replace) ⇒ Object Also known as: gsub
19 20 21 22 23 24 25 |
# File 'lib/verto/dsl/file.rb', line 19 def replace_all(to_match, to_replace) content = file.read file.open('w') do |f| f << content.gsub(to_match, to_replace) end end |