Class: Protobug::Compiler::Builder::Group

Inherits:
Struct
  • Object
show all
Includes:
Protobug::Compiler::Builder
Defined in:
lib/protobug/compiler/builder.rb,
lib/protobug/compiler/builder_gen.rb

Direct Known Subclasses

File

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Protobug::Compiler::Builder

build_file

Instance Attribute Details

#closeObject

Returns the value of attribute close

Returns:

  • (Object)

    the current value of close



92
93
94
# File 'lib/protobug/compiler/builder.rb', line 92

def close
  @close
end

#indentObject

Returns the value of attribute indent

Returns:

  • (Object)

    the current value of indent



92
93
94
# File 'lib/protobug/compiler/builder.rb', line 92

def indent
  @indent
end

#itemsObject

Returns the value of attribute items

Returns:

  • (Object)

    the current value of items



92
93
94
# File 'lib/protobug/compiler/builder.rb', line 92

def items
  @items
end

#multiObject

Returns the value of attribute multi

Returns:

  • (Object)

    the current value of multi



92
93
94
# File 'lib/protobug/compiler/builder.rb', line 92

def multi
  @multi
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



92
93
94
# File 'lib/protobug/compiler/builder.rb', line 92

def name
  @name
end

#openObject

Returns the value of attribute open

Returns:

  • (Object)

    the current value of open



92
93
94
# File 'lib/protobug/compiler/builder.rb', line 92

def open
  @open
end

#separatorObject

Returns the value of attribute separator

Returns:

  • (Object)

    the current value of separator



92
93
94
# File 'lib/protobug/compiler/builder.rb', line 92

def separator
  @separator
end

Instance Method Details

#_classObject



61
62
63
# File 'lib/protobug/compiler/builder_gen.rb', line 61

def _class
  append Statement.new._class
end

#_defObject



65
66
67
# File 'lib/protobug/compiler/builder_gen.rb', line 65

def _def
  append Statement.new._def
end

#_moduleObject



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

Returns:

  • (Boolean)


149
# File 'lib/protobug/compiler/builder.rb', line 149

def compact? = false

#emptyObject



100
101
102
# File 'lib/protobug/compiler/builder.rb', line 100

def empty
  append Statement.new.empty
end

#empty?Boolean

Returns:

  • (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