• 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
14require 'ostruct'
15require 'delegate'
16
17class Level
18  attr_reader :name
19  attr_reader :value
20  attr_reader :enum
21  attr_reader :tag
22
23  def initialize(dscr)
24     @dscr = dscr
25     @name = dscr['name']
26     @value = dscr['value']
27     @enum = dscr['enum'] || @name.upcase
28     @tag = dscr['tag'] || @name[0].upcase
29  end
30end
31
32class Component
33  attr_reader :name
34  attr_reader :enum
35
36  def initialize(dscr)
37    @dscr = dscr
38    @name = dscr['name']
39    @enum = dscr['enum'] || @name.upcase
40  end
41end
42
43module LoggerData
44  module_function
45
46  def levels
47    @levels
48  end
49
50  def components
51    @components
52  end
53
54  def dfx_components
55    @dfx_components
56  end
57
58  def wrap_data(data)
59    @data = data
60    @levels = data.levels.map { |op| Level.new(op) }
61    @components = data.components.map { |op| Component.new(op) }
62    @dfx_components = data.dfx_components.map { |op| Component.new(op) }
63  end
64end
65
66def Gen.on_require(data)
67  LoggerData.wrap_data(data)
68end
69