Class: SPQR::AppBoilerplateGenerator

Inherits:
Object
  • Object
show all
Includes:
PrettyPrinter
Defined in:
lib/spqr/codegen.rb

Instance Method Summary collapse

Methods included from PrettyPrinter

#dec_indent, #inc_indent, #indent, #outfile, #pp, #pp_call, #pp_decl, #pp_invoke, #stack, #with_output_to, #writemode

Constructor Details

#initialize(scs, fn) ⇒ AppBoilerplateGenerator

scs is a list of schemaclass objects, fn is an output filename



366
367
368
369
# File 'lib/spqr/codegen.rb', line 366

def initialize(scs, fn)
  @scs = scs
  @fn = fn
end

Instance Method Details

#genObject

cc is the name of the variable that will hold a collection of schema classes



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/spqr/codegen.rb', line 372

def gen
  with_output_to @fn do
    pp "require 'spqr/spqr'"
    pp "require 'spqr/app'"

    pp ""

    @scs.each do |sc|
      pp("require '#{sc.package.gsub(/[.]/, '/')}/#{sc.name}'")
    end

    
    pp ""
    
    pp "app = SPQR::App.new(:loglevel => :debug)"
    
    klass_list = @scs.collect do |sc|
      (sc.package.split(".").collect{|pkg| pkg.capitalize} << sc.name).join("::")
    end
    
    pp "app.register #{klass_list.join ','}"
    
    pp ""

    pp "app.main"
  end
end