Class: Enterprisifier::CodeGeneration::CodeBuilder
- Inherits:
-
Object
- Object
- Enterprisifier::CodeGeneration::CodeBuilder
- Defined in:
- lib/enterprisifier/code_generation/code_builder.rb
Constant Summary collapse
- IndentationLevel =
2
Instance Method Summary collapse
- #<<(string) ⇒ Object
- #blank? ⇒ Boolean
- #indent ⇒ Object
-
#initialize(indentation = 0) ⇒ CodeBuilder
constructor
A new instance of CodeBuilder.
- #to_s ⇒ Object
Constructor Details
#initialize(indentation = 0) ⇒ CodeBuilder
Returns a new instance of CodeBuilder.
5 6 7 8 |
# File 'lib/enterprisifier/code_generation/code_builder.rb', line 5 def initialize(indentation = 0) @code = '' @indentation = indentation end |
Instance Method Details
#<<(string) ⇒ Object
10 11 12 13 14 |
# File 'lib/enterprisifier/code_generation/code_builder.rb', line 10 def <<(string) string.to_s.each_line do |line| @code << "#{" " * @indentation}#{line.chomp}\n" end end |
#blank? ⇒ Boolean
27 28 29 |
# File 'lib/enterprisifier/code_generation/code_builder.rb', line 27 def blank? @code.blank? end |
#indent ⇒ Object
16 17 18 19 20 21 |
# File 'lib/enterprisifier/code_generation/code_builder.rb', line 16 def indent @indentation += IndentationLevel yield ensure @indentation -= IndentationLevel end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/enterprisifier/code_generation/code_builder.rb', line 23 def to_s @code end |