Class: Kubes::Compiler::Strategy::Erb::Comment

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/kubes/compiler/strategy/erb/comment.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Comment

Returns a new instance of Comment.



11
12
13
# File 'lib/kubes/compiler/strategy/erb/comment.rb', line 11

def initialize(path)
  @path = path
end

Instance Method Details

#cleanObject



38
39
40
# File 'lib/kubes/compiler/strategy/erb/comment.rb', line 38

def clean
  FileUtils.rm_f(erb_path) unless ENV['KUBES_KEEP_ERB']
end

#erb_pathObject



42
43
44
# File 'lib/kubes/compiler/strategy/erb/comment.rb', line 42

def erb_path
  "#{@path}.erb"
end

#linesObject



15
16
17
# File 'lib/kubes/compiler/strategy/erb/comment.rb', line 15

def lines
  IO.readlines(@path)
end

#processObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kubes/compiler/strategy/erb/comment.rb', line 24

def process
  new_lines = lines.map do |line|
    md = line.match(/(.*)#ERB(.*)/)
    if md
      "#{md[1]}<%#{md[2]} %>\n"
    else
      line
    end
  end
  content = new_lines.join('')
  IO.write(erb_path, content)
  erb_path
end

#process?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/kubes/compiler/strategy/erb/comment.rb', line 20

def process?
  !!lines.detect { |l| l.include?('#ERB') }
end