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)



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

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

Class Method Details

.load(path) ⇒ Inquirex::Definition

Parameters:

  • path (String)

    path to a .rb flow definition file

Returns:

  • (Inquirex::Definition)

Raises:



12
13
14
# File 'lib/inquirex/tty/flow_loader.rb', line 12

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

Instance Method Details

#loadInquirex::Definition

Returns:

  • (Inquirex::Definition)

Raises:



24
25
26
27
28
29
30
31
# File 'lib/inquirex/tty/flow_loader.rb', line 24

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