Class: Mutant::Loader Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mutant/loader.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

FROZEN_STRING_FORMAT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"# frozen_string_literal: true\n%s"
VOID_VALUE_REGEXP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/\A[^:]+:\d+: void value expression/
VOID_VALUE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Either::Left.new(nil)
SUCCESS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Either::Right.new(nil)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(*arguments) ⇒ Result

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Call loader

Returns:



18
19
20
# File 'lib/mutant/loader.rb', line 18

def self.call(*arguments)
  new(*arguments).call
end

Instance Method Details

#callResult

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Call loader

One off the very few valid uses of eval ever.

rubocop:disable Metrics/MethodLength

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mutant/loader.rb', line 29

def call
  kernel.eval(
    FROZEN_STRING_FORMAT % source,
    binding,
    subject.source_path.to_s,
    subject.source_line
  )
rescue SyntaxError => exception
  # rubocop:disable Style/GuardClause
  if VOID_VALUE_REGEXP.match?(exception.message)
    VOID_VALUE
  else
    raise
  end
else
  SUCCESS
end