class MonkeyKing::Parser

Public Instance Methods

get_tags(yaml_file) click to toggle source
# File lib/monkey_king/parser.rb, line 152
def get_tags(yaml_file)
  tags = []
  nodes = Psych.parse_file(yaml_file)
  # traverse the tree and return
  nodes.each do |n|
    if n.class == Psych::Nodes::Scalar
      unless n.tag.nil?
        tags << n.tag
      end
    end
  end
  tags.uniq
end
transform(yaml_file) click to toggle source
# File lib/monkey_king/parser.rb, line 133
def transform(yaml_file)
  function_tag_instances = {}
  tags = get_tags(yaml_file)

  tags.each do |tag|
    if tag =~ /!MK:/
      tag_class = Class.new(FunctionTag)
      random_string = SecureRandom.uuid.gsub(/-/, '')
      Object.const_set("FunctionTag#{random_string}", tag_class)
      tag_instance = tag_class.new
      tag_instance.register(tag)
      function_tag_instances[tag] = tag_instance
    end
  end

  yaml = YAML.load_file(yaml_file)
  yaml.to_yaml
end