Sha256: 56edbad367d57a1597ac86c0ef2075eb63357152d026a177ed6a25e9a2f546cb

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

require_relative "../../utils/project"

# DSL module methods: assert, missing_method
module DSL
  ##
  # Invoke macro
  # @param name (String) Macro name
  # @param input (Hash) Macro params
  def macro(name, input = {})
    macros = Project.value[:macros]
    unless macros[name]
      log("Macro #{name} not found!", :error)
      return
    end
    input.each_pair { |k, v| set(k, v) }
    errors = []
    macros[name][:args].each do |i|
      errors << i if get(i) == "NODATA"
    end
    if errors.count > 0
      log("Macro #{name} => required params #{errors.join(",")}", :error)
    else
      instance_eval(&macros[name][:block])
    end
    input.each_pair { |k, v| unset(k) }
  end

  # If a method call is missing, then:
  # * delegate to concept parent.
  # * Invoke macro (assert)
  def method_missing(method, args = {})
    a = method.to_s
    if a.start_with?("_")
      return instance_eval("get(:#{a[1, a.size - 1]})", __FILE__, __LINE__)
    end
    return macro a[6, a.size], args if a[0, 6] == "macro_"
    macro a, args
  end

  def respond_to_missing?(method, *)
    true
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
teuton-2.7.3 lib/teuton/case/dsl/macro.rb
teuton-2.7.2 lib/teuton/case/dsl/macro.rb
teuton-2.7.1 lib/teuton/case/dsl/macro.rb
teuton-2.7.0 lib/teuton/case/dsl/macro.rb