|
| 1 | +# |
| 2 | +# vim: syntax=ruby:expandtab:shiftwidth=2:softtabstop=2:tabstop=2 |
| 3 | +# |
| 4 | +# Copyright (c) 2025-present, Meta Platforms, Inc. |
| 5 | +# Copyright (c) 2025-present, Phil Dibowitz |
| 6 | +# All rights reserved. |
| 7 | +# |
| 8 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | +# you may not use this file except in compliance with the License. |
| 10 | +# You may obtain a copy of the License at |
| 11 | +# |
| 12 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | +# |
| 14 | +# Unless required by applicable law or agreed to in writing, software |
| 15 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | +# See the License for the specific language governing permissions and |
| 18 | +# limitations under the License. |
| 19 | +# |
| 20 | + |
| 21 | +module FB |
| 22 | + class InfluxDB |
| 23 | + def self.indentstr(indent) |
| 24 | + ' ' * indent |
| 25 | + end |
| 26 | + |
| 27 | + def self.handle_raw_val(val) |
| 28 | + val.is_a?(String) ? "\"#{val}\"" : val.to_s |
| 29 | + end |
| 30 | + |
| 31 | + def self.template_hash_helper(buf, indent, data) |
| 32 | + data.each do |key, val| |
| 33 | + buf << indentstr(indent + 1) |
| 34 | + case val |
| 35 | + when Array |
| 36 | + buf << "#{key} = [\n" |
| 37 | + val.each do |item| |
| 38 | + buf << indentstr(indent + 2) |
| 39 | + buf << "#{handle_raw_val(item)},\n" |
| 40 | + end |
| 41 | + buf << indentstr(indent + 1) |
| 42 | + buf << "]\n" |
| 43 | + when Hash |
| 44 | + template_hash_helper(buf, indent + 1, data) |
| 45 | + else |
| 46 | + buf << "#{key} = #{handle_raw_val(val)}\n" |
| 47 | + end |
| 48 | + end |
| 49 | + end |
| 50 | + end |
| 51 | +end |
0 commit comments