Class: Enterprisifier::CodeGeneration::CodeBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/enterprisifier/code_generation/code_builder.rb

Constant Summary collapse

IndentationLevel =
2

Instance Method Summary collapse

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

Returns:

  • (Boolean)


27
28
29
# File 'lib/enterprisifier/code_generation/code_builder.rb', line 27

def blank?
  @code.blank?
end

#indentObject



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_sObject



23
24
25
# File 'lib/enterprisifier/code_generation/code_builder.rb', line 23

def to_s
  @code
end