Class: Protobug::Compiler::Builder::Group
- Inherits:
-
Struct
- Object
- Struct
- Protobug::Compiler::Builder::Group
- Includes:
- Protobug::Compiler::Builder
- Defined in:
- lib/protobug/compiler/builder.rb,
lib/protobug/compiler/builder_gen.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#close ⇒ Object
Returns the value of attribute close.
-
#indent ⇒ Object
Returns the value of attribute indent.
-
#items ⇒ Object
Returns the value of attribute items.
-
#multi ⇒ Object
Returns the value of attribute multi.
-
#name ⇒ Object
Returns the value of attribute name.
-
#open ⇒ Object
Returns the value of attribute open.
-
#separator ⇒ Object
Returns the value of attribute separator.
Instance Method Summary collapse
- #_class ⇒ Object
- #_def ⇒ Object
- #_module ⇒ Object
- #append(item) ⇒ Object
- #block(&blk) ⇒ Object
- #comment(text) ⇒ Object
- #compact? ⇒ Boolean
- #empty ⇒ Object
- #empty? ⇒ Boolean
- #identifier(name) ⇒ Object
- #literal(content) ⇒ Object
- #op(operator) ⇒ Object
-
#render(q) ⇒ Object
rubocop:disable Naming/MethodParameterName.
Methods included from Protobug::Compiler::Builder
Instance Attribute Details
#close ⇒ Object
Returns the value of attribute close
92 93 94 |
# File 'lib/protobug/compiler/builder.rb', line 92 def close @close end |
#indent ⇒ Object
Returns the value of attribute indent
92 93 94 |
# File 'lib/protobug/compiler/builder.rb', line 92 def indent @indent end |
#items ⇒ Object
Returns the value of attribute items
92 93 94 |
# File 'lib/protobug/compiler/builder.rb', line 92 def items @items end |
#multi ⇒ Object
Returns the value of attribute multi
92 93 94 |
# File 'lib/protobug/compiler/builder.rb', line 92 def multi @multi end |
#name ⇒ Object
Returns the value of attribute name
92 93 94 |
# File 'lib/protobug/compiler/builder.rb', line 92 def name @name end |
#open ⇒ Object
Returns the value of attribute open
92 93 94 |
# File 'lib/protobug/compiler/builder.rb', line 92 def open @open end |
#separator ⇒ Object
Returns the value of attribute separator
92 93 94 |
# File 'lib/protobug/compiler/builder.rb', line 92 def separator @separator end |
Instance Method Details
#_class ⇒ Object
61 62 63 |
# File 'lib/protobug/compiler/builder_gen.rb', line 61 def _class append Statement.new._class end |
#_def ⇒ Object
65 66 67 |
# File 'lib/protobug/compiler/builder_gen.rb', line 65 def _def append Statement.new._def end |
#_module ⇒ Object
69 70 71 |
# File 'lib/protobug/compiler/builder_gen.rb', line 69 def _module append Statement.new._module end |
#append(item) ⇒ Object
138 139 140 141 |
# File 'lib/protobug/compiler/builder.rb', line 138 def append(item) items << item item end |
#block(&blk) ⇒ Object
104 105 106 |
# File 'lib/protobug/compiler/builder.rb', line 104 def block(&blk) append Statement.new.block(&blk) end |
#comment(text) ⇒ Object
96 97 98 |
# File 'lib/protobug/compiler/builder.rb', line 96 def comment(text) append Statement.new.comment(text) end |
#compact? ⇒ Boolean
149 |
# File 'lib/protobug/compiler/builder.rb', line 149 def compact? = false |
#empty ⇒ Object
100 101 102 |
# File 'lib/protobug/compiler/builder.rb', line 100 def empty append Statement.new.empty end |
#empty? ⇒ Boolean
143 144 145 146 147 |
# File 'lib/protobug/compiler/builder.rb', line 143 def empty? return false if name != :call && (open || close) items.none? { |item| !item.empty? } end |
#identifier(name) ⇒ Object
108 109 110 |
# File 'lib/protobug/compiler/builder.rb', line 108 def identifier(name) append Statement.new.identifier(name) end |
#literal(content) ⇒ Object
112 113 114 |
# File 'lib/protobug/compiler/builder.rb', line 112 def literal(content) append Statement.new.literal(content) end |
#op(operator) ⇒ Object
116 117 118 |
# File 'lib/protobug/compiler/builder.rb', line 116 def op(operator) append Statement.new.op(operator) end |
#render(q) ⇒ Object
rubocop:disable Naming/MethodParameterName
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/protobug/compiler/builder.rb', line 120 def render(q) # rubocop:disable Naming/MethodParameterName if name == "block" && empty? q.breakable "; " q.text "end" end q.group do q.text open if open q.nest(indent || 0) do write_items(q) end return unless close multi ? q.breakable_force : q.breakable_empty q.text close end end |