Class: Protobug::Compiler::Builder::File

Inherits:
Group
  • Object
show all
Defined in:
lib/protobug/compiler/builder.rb

Instance Attribute Summary

Attributes inherited from Group

#close, #indent, #items, #multi, #name, #open, #separator

Instance Method Summary collapse

Methods inherited from Group

#_class, #_def, #_module, #append, #block, #comment, #compact?, #empty, #empty?, #identifier, #literal, #op

Methods included from Protobug::Compiler::Builder

build_file

Constructor Details

#initializeFile

Returns a new instance of File.



173
174
175
176
# File 'lib/protobug/compiler/builder.rb', line 173

def initialize
  @headers = []
  super(Group.new(name: "file", items: [], multi: true))
end

Instance Method Details

#header_comment(text) ⇒ Object



178
179
180
# File 'lib/protobug/compiler/builder.rb', line 178

def header_comment(text)
  @headers << text
end

#renderObject



182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/protobug/compiler/builder.rb', line 182

def render
  q = PrettierPrint.new(+"")
  @headers.each_with_index do |header, idx|
    q.breakable_force if idx.positive?
    Comment.new(header).render(q)
    q.breakable_force
  end
  super(q)
  q.trim
  q.breakable_force
  q.flush
  q.output
end