Class: DeclareSchema::Support::IndentedBuffer
- Inherits:
-
Object
- Object
- DeclareSchema::Support::IndentedBuffer
- Defined in:
- lib/generators/declare_schema/support/model.rb
Instance Method Summary collapse
- #<<(str) ⇒ Object
- #indent! ⇒ Object
-
#initialize(indent: 0) ⇒ IndentedBuffer
constructor
A new instance of IndentedBuffer.
- #newline! ⇒ Object
- #to_string ⇒ Object
Constructor Details
#initialize(indent: 0) ⇒ IndentedBuffer
Returns a new instance of IndentedBuffer.
8 9 10 11 12 13 |
# File 'lib/generators/declare_schema/support/model.rb', line 8 def initialize(indent: 0) @string = +"" @indent = indent @column = 0 @indent_amount = 2 end |
Instance Method Details
#<<(str) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/generators/declare_schema/support/model.rb', line 30 def <<(str) if (difference = @indent - @column) > 0 @string << ' ' * difference end @column += difference @string << str newline! end |
#indent! ⇒ Object
19 20 21 22 23 |
# File 'lib/generators/declare_schema/support/model.rb', line 19 def indent! @indent += @indent_amount yield @indent -= @indent_amount end |
#newline! ⇒ Object
25 26 27 28 |
# File 'lib/generators/declare_schema/support/model.rb', line 25 def newline! @column = 0 @string << "\n" end |
#to_string ⇒ Object
15 16 17 |
# File 'lib/generators/declare_schema/support/model.rb', line 15 def to_string @string end |