Class: Ynl::Family

Inherits:
Object
  • Object
show all
Defined in:
ynl/lib/ynl/family.rb

Overview

Entry points for generating family classes from YNL specifications.

Class Method Summary collapse

Class Method Details

.build(path) ⇒ Class<Nl::Family>

Builds a family class from a YNL specification file.

Parameters:

  • path (String, #to_path) —

    a path to a YNL specification file

Returns:

  • (Class<Nl::Family>) —

    the generated family class



14
15
16
17
18
19
# File 'ynl/lib/ynl/family.rb', line 14

def self.build(path)
  buf = StringIO.new(Generator::PRELUDE.dup)
  classname = File.open(path) {|f| generate(f, buf, namespace: 'self') }

  Module.new { eval(buf.string) }.const_get(classname)
end

.generate(source, out, **kwargs) ⇒ String

Generates Ruby source code to define a family class from a YNL specification.

Parameters:

  • source (String, #read) —

    a YAML string or readable IO containing the YNL specification

  • out (#write) —

    the destination for the generated source code

  • kwargs (Hash) —

    a customizable set of options

Options Hash (**kwargs):

  • superclass (String, nil) —

    the name of the generated class's superclass

  • namespace (String, nil) —

    the namespace in which to define the family class

  • default_resolver (String, nil) —

    the expression used as the default family resolver

Returns:

  • (String) —

    the generated family class name



30
31
32
# File 'ynl/lib/ynl/family.rb', line 30

def self.generate(source, out, **kwargs)
  Generator.new(Ynl::Parser.new(source).parse, out).generate(**kwargs)
end