• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14module Generator
15  class Definitions
16    def initialize(data)
17      # YAML:
18      #   - name: Generator::DEF_TEMPLATE_NAME
19      #     template: Generator::DEF_TEMPLATE
20      @data = data
21    end
22
23    def definition(item_name)
24      LOG.debug "search for '#{item_name}' definition"
25      @data.each do |item|
26        LOG.debug "check #{item}"
27
28        if item.key?(Generator::DEF_TEMPLATE_NAME) && item[Generator::DEF_TEMPLATE_NAME] == item_name
29          return item[Generator::DEF_TEMPLATE]
30        end
31      end
32      raise "Definition of '#{item_name}' is not found"
33    end
34
35    def exist? (item_name)
36      LOG.debug "check #{item_name} exists in definitions"
37      @data.each do |item|
38        if item.key?(Generator::DEF_TEMPLATE_NAME) && item[Generator::DEF_TEMPLATE_NAME] == item_name
39          return true
40        end
41      end
42      return false
43    end
44  end
45end
46