class Verto::DSL::Interpreter

Constants

Error

TODO: Wrap stacktrace

Public Instance Methods

evaluate(vertofile_content = nil, attributes: {}, &block) click to toggle source
# File lib/verto/dsl/interpreter.rb, line 11
def evaluate(vertofile_content = nil, attributes: {}, &block)
  with_attributes(attributes) do
    vertofile_content ? instance_eval(vertofile_content) : instance_eval(&block)
  end
rescue StandardError => e
  raise e if e.is_a?(Verto::ExitError)

  raise Error, e.message
end

Private Instance Methods

with_attributes(attributes, &block) click to toggle source
# File lib/verto/dsl/interpreter.rb, line 23
def with_attributes(attributes, &block)
  attributes.each do |key, value|
    instance_variable_set("@#{key}", value)
    define_singleton_method(key) { instance_variable_get("@#{key}") }
  end

  block.call

  attributes.each do |key, _value|
    instance_variable_set("@#{key}", nil)
    singleton_class.remove_method(key)
  end
end