Sha256: b3243d4da6aeae3c07ef39f2f072f1ee1ea37e4bdd03193dcb3a479e04ab90b6

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true
require_relative '../../../application'

# 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 = Application.instance.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
    return instance_eval("get(:#{a[0, a.size - 1]})") if a[a.size - 1] == '?'
    return macro a[6, a.size], args if a[0,6]=='macro_'
    macro a, args
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
teuton-2.1.10 lib/teuton/case_manager/case/dsl/macro.rb
teuton-2.1.9 lib/teuton/case_manager/case/dsl/macro.rb