Class: Inquirex::TTY::FlowLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/inquirex/tty/flow_loader.rb

Overview

Loads a flow definition from a Ruby file by evaluating it in a top-level binding. The file is expected to call Inquirex.define and return an Inquirex::Definition.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FlowLoader

Returns a new instance of FlowLoader.

Parameters:

  • path (String)

    path (will be expanded)



23
24
25
26
# File 'lib/inquirex/tty/flow_loader.rb', line 23

def initialize(path)
  @path = File.expand_path(path)
  validate_path!
end

Class Method Details

.load(path) ⇒ Inquirex::Definition

Loads and evaluates a flow definition file in one call.

Examples:

Load a flow definition from disk

definition = Inquirex::TTY::FlowLoader.load("examples/08_tax_preparer.rb")
definition.step_ids # => [:filing_status, :dependents, ...]

Parameters:

  • path (String)

    path to a .rb flow definition file

Returns:

  • (Inquirex::Definition)

Raises:



18
19
20
# File 'lib/inquirex/tty/flow_loader.rb', line 18

def self.load(path)
  new(path).load
end

Instance Method Details

#loadInquirex::Definition

Returns:

  • (Inquirex::Definition)

Raises:



30
31
32
33
34
35
36
37
# File 'lib/inquirex/tty/flow_loader.rb', line 30

def load
  content = File.read(@path)
  # rubocop:disable Security/Eval
  eval(content, TOPLEVEL_BINDING.dup, @path, 1)
  # rubocop:enable Security/Eval
rescue SyntaxError => e
  raise Inquirex::TTY::Error, "Syntax error in #{@path}: #{e.message}"
end