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



94
95
96
# File 'lib/protobug/compiler/builder.rb', line 94

def close
  @close
end

#indentObject

Returns the value of attribute indent

Returns:

  • (Object)

    the current value of indent



94
95
96
# File 'lib/protobug/compiler/builder.rb', line 94

def indent
  @indent
end

#itemsObject

Returns the value of attribute items

Returns:

  • (Object)

    the current value of items



94
95
96
# File 'lib/protobug/compiler/builder.rb', line 94

def items
  @items
end

#multiObject

Returns the value of attribute multi

Returns:

  • (Object)

    the current value of multi



94
95
96
# File 'lib/protobug/compiler/builder.rb', line 94

def multi
  @multi
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



94
95
96
# File 'lib/protobug/compiler/builder.rb', line 94

def name
  @name
end

#openObject

Returns the value of attribute open

Returns:

  • (Object)

    the current value of open



94
95
96
# File 'lib/protobug/compiler/builder.rb', line 94

def open
  @open
end

#separatorObject

Returns the value of attribute separator

Returns:

  • (Object)

    the current value of separator



94
95
96
# File 'lib/protobug/compiler/builder.rb', line 94

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



140
141
142
143
# File 'lib/protobug/compiler/builder.rb', line 140

def append(item)
  items << item
  item
end

#block(&blk) ⇒ Object



106
107
108
# File 'lib/protobug/compiler/builder.rb', line 106

def block(&blk)
  append Statement.new.block(&blk)
end

#comment(text) ⇒ Object



98
99
100
# File 'lib/protobug/compiler/builder.rb', line 98

def comment(text)
  append Statement.new.comment(text)
end

#compact?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/protobug/compiler/builder.rb', line 151

def compact?
  false
end

#emptyObject



102
103
104
# File 'lib/protobug/compiler/builder.rb', line 102

def empty
  append Statement.new.empty
end

#empty?Boolean

Returns:

  • (Boolean)


145
146
147
148
149
# File 'lib/protobug/compiler/builder.rb', line 145

def empty?
  return false if name != :call && (open || close)

  items.none? { |item| !item.empty? }
end

#identifier(name) ⇒ Object



110
111
112
# File 'lib/protobug/compiler/builder.rb', line 110

def identifier(name)
  append Statement.new.identifier(name)
end

#literal(content) ⇒ Object



114
115
116
# File 'lib/protobug/compiler/builder.rb', line 114

def literal(content)
  append Statement.new.literal(content)
end

#op(operator) ⇒ Object



118
119
120
# File 'lib/protobug/compiler/builder.rb', line 118

def op(operator)
  append Statement.new.op(operator)
end

#render(q) ⇒ Object

rubocop:disable Naming/MethodParameterName



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/protobug/compiler/builder.rb', line 122

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