class Campa::Core::Load

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

Attributes

evaler[R]

Public Class Methods

new() click to toggle source
# File lib/campa/core/load.rb, line 7
def initialize
  @evaler = Evaler.new
end

Public Instance Methods

call(*paths, env:) click to toggle source

@param paths [Array<String>] Strings representing paths to files

to be evaled in a given context

@param env [Context] where the files pointed by paths

will be evaled

@return [Object] value of the last form evaled from the last file

given by <i>paths</i>
# 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

Private Instance Methods

verify_presence(paths) click to toggle source
# File lib/campa/core/load.rb, line 29
def verify_presence(paths)
  not_here = paths.find { |f| !File.file?(File.expand_path(f)) }
  raise Error::NotFound, not_here if !not_here.nil?
end