Module: Kumi::Frontends::Ruby

Defined in:
lib/kumi/frontends/ruby.rb

Class Method Summary collapse

Class Method Details

.load(path:, inputs: {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kumi/frontends/ruby.rb', line 8

def load(path:, inputs: {})
  mod = Module.new
  mod.extend(Kumi::Schema)
  mod.module_eval(File.read(path), path)

  # Extract just the syntax tree AST (same as Text frontend)
  schema_ast = if mod.const_defined?(:GoldenSchema)
                 golden = mod.const_get(:GoldenSchema)
                 golden.build if golden.respond_to?(:build)
                 golden.__syntax_tree__
               elsif mod.__syntax_tree__
                 mod.__syntax_tree__
               else
                 raise "No schema AST found. Make sure the .rb file calls 'schema do...end'"
               end

  [schema_ast, inputs]
end