module Steamd::Generator::Implementation
The underlying Implementation
of a generator.
@example Making a generate
class MyGenerator include Generator::Implementation def generate classes.each { |c| puts c.name } end end
Public Class Methods
new(io)
click to toggle source
Instantiate the object with a given IO stream.
@param io The IO object
# File lib/steamd/generator/implementation.rb, line 25 def initialize(io) @parser = Steamd::Parser.new @buffer = '' @io = io self end
Public Instance Methods
classes()
click to toggle source
The classes parsed from the lanaguage
# File lib/steamd/generator/implementation.rb, line 43 def classes @parser.classes.map do |klass| GeneratedClass.new(klass) end end
enums()
click to toggle source
The enums parsed from the language
# File lib/steamd/generator/implementation.rb, line 57 def enums @parser.enums.map do |enum| GeneratedEnum.new(enum) end end
imports()
click to toggle source
The imports parsed from the language
# File lib/steamd/generator/implementation.rb, line 50 def imports @parser.imports.map do |import| GeneratedImport.new(import) end end
run()
click to toggle source
Run the generator. Load the parser, and parse the IO object.
@return The parsed code
# File lib/steamd/generator/implementation.rb, line 35 def run @parser.load! @parser.parse(@io) generate @buffer end
Private Instance Methods
append(str)
click to toggle source
Append a string to the internal buffer
@api private
# File lib/steamd/generator/implementation.rb, line 78 def append(str) @buffer += str end
erb(template, vars)
click to toggle source
@api private
# File lib/steamd/generator/implementation.rb, line 71 def erb(template, vars) ERB.new(template, nil, '-').result(vars.erb_binding) end
generate(_io)
click to toggle source
Generates the code
# File lib/steamd/generator/implementation.rb, line 66 def generate(_io) raise NotImplementedError end