Class: ActionController::CodeGeneration::Source

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

Overview

:nodoc:

Constant Summary collapse

IndentationString =
'  '

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSource

Returns a new instance of Source.



9
10
11
# File 'lib/action_controller/code_generation.rb', line 9

def initialize
  @lines, @indentation_level = [], 0
end

Instance Attribute Details

#indentation_levelObject (readonly)

Returns the value of attribute indentation_level.



7
8
9
# File 'lib/action_controller/code_generation.rb', line 7

def indentation_level
  @indentation_level
end

#linesObject (readonly)

Returns the value of attribute lines.



7
8
9
# File 'lib/action_controller/code_generation.rb', line 7

def lines
  @lines
end

Instance Method Details

#indentObject



17
18
19
20
21
22
# File 'lib/action_controller/code_generation.rb', line 17

def indent
  @indentation_level += 1
  yield
  ensure
  @indentation_level -= 1
end

#line(line) ⇒ Object Also known as: <<



12
13
14
# File 'lib/action_controller/code_generation.rb', line 12

def line(line)
  @lines << (IndentationString * @indentation_level + line)
end

#to_sObject



24
# File 'lib/action_controller/code_generation.rb', line 24

def to_s() lines.join("\n") end