Class: Verto::DSL::File

Inherits:
Object
  • Object
show all
Defined in:
lib/verto/dsl/file.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename, path: Verto.config.project.path) ⇒ File

Returns a new instance of File.



6
7
8
9
# File 'lib/verto/dsl/file.rb', line 6

def initialize(filename, path: Verto.config.project.path)
  @filename = filename
  @path = Pathname.new(path)
end

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