Class: Kubes::Compiler::Strategy::Erb::Comment
- Inherits:
-
Object
- Object
- Kubes::Compiler::Strategy::Erb::Comment
- Extended by:
- Memoist
- Defined in:
- lib/kubes/compiler/strategy/erb/comment.rb
Instance Method Summary collapse
- #clean ⇒ Object
- #erb_path ⇒ Object
-
#initialize(path) ⇒ Comment
constructor
A new instance of Comment.
- #lines ⇒ Object
- #process ⇒ Object
- #process? ⇒ Boolean
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
#clean ⇒ Object
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_path ⇒ Object
42 43 44 |
# File 'lib/kubes/compiler/strategy/erb/comment.rb', line 42 def erb_path "#{@path}.erb" end |
#lines ⇒ Object
15 16 17 |
# File 'lib/kubes/compiler/strategy/erb/comment.rb', line 15 def lines IO.readlines(@path) end |
#process ⇒ Object
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
20 21 22 |
# File 'lib/kubes/compiler/strategy/erb/comment.rb', line 20 def process? !!lines.detect { |l| l.include?('#ERB') } end |