Module: Kumi::Frontends

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

Defined Under Namespace

Modules: Ruby, Text

Class Method Summary collapse

Class Method Details

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



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

def self.load(path:, inputs: {})
  mode = ENV["KUMI_PARSER"] || "auto" # auto|text|ruby
  ext  = File.extname(path)

  # Explicit mode selection
  return Text.load(path:, inputs:) if mode == "text"
  return Ruby.load(path:, inputs:) if mode == "ruby"

  # Auto mode: prefer .kumi if present
  if mode == "auto" && ext == ".rb"
    kumi_path = path.sub(/\.rb\z/, ".kumi")
    return Text.load(path: kumi_path, inputs: inputs) if File.exist?(kumi_path)
  end

  # File extension based selection
  return Text.load(path:, inputs:) if ext == ".kumi"
  return Ruby.load(path:, inputs:) if ext == ".rb"

  # Default fallback
  Ruby.load(path:, inputs:)
end