Class: Campa::Core::Load

Inherits:
Object
  • Object
show all
Defined in:
lib/campa/core/load.rb

Overview

Implements a Campa function that reads (Reader) and evaluates (Evaler) files with valid Campa code in the given Campa::Context.

Instance Method Summary collapse

Constructor Details

#initializeLoad

Returns a new instance of Load.



7
8
9
# File 'lib/campa/core/load.rb', line 7

def initialize
  @evaler = Evaler.new
end

Instance Method Details

#call(*paths, env:) ⇒ Object

Returns value of the last form evaled from the last file given by paths.

Parameters:

  • paths (Array<String>)

    Strings representing paths to files to be evaled in a given context

  • env (Context)

    where the files pointed by paths will be evaled

Returns:

  • (Object)

    value of the last form evaled from the last file given by paths



17
18
19
20
21
22
23
# File 'lib/campa/core/load.rb', line 17

def call(*paths, env:)
  verify_presence(paths)
  paths.reduce(nil) do |_, file|
    reader = Reader.new(File.expand_path(file))
    evaler.eval(reader, env)
  end
end