Module: Fluentd::Setting::Configurable::ClassMethods

Defined in:
app/models/concerns/fluentd/setting/configurable.rb

Instance Method Summary collapse

Instance Method Details

#config_argument(name, type = ActiveModel::Type::Value.new, **options) ⇒ Object



101
102
103
104
# File 'app/models/concerns/fluentd/setting/configurable.rb', line 101

def config_argument(name, type = ActiveModel::Type::Value.new, **options)
  config_param(name, type, **options)
  set_argument_name(name)
end

#config_param(name, type = ActiveModel::Type::Value.new, **options) ⇒ Object

config_param :name, :string, default: “value”, secret: true



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/concerns/fluentd/setting/configurable.rb', line 55

def config_param(name, type = ActiveModel::Type::Value.new, **options)
  # NOTE: We cannot overwrite types defined by ActiveModel in config/initializers/types.rb
  if type == :time
    type = Fluentd::Setting::Type::Time.new
  end
  if name.to_s.start_with?("@")
    _name = name.to_s[1..-1]
    config_param(_name.to_sym, type, **options.merge(alias: name))
    self._built_in_params << _name
  elsif ["id", "type", "log_level"].include?(name.to_s)
    self._built_in_params << name
    unless name == "type"
      attribute(name, type, **options.slice(:precision, :limit, :scale))
    end
  else
    attribute(name, type, **options.slice(:precision, :limit, :scale))
  end
  self._types[name] = type
  self._descriptions[name] = options[:desc] if options.key?(:desc)
  self._defaults[name] = options[:default] if options.key?(:default)
  self._secrets[name] = options[:secret] if options.key?(:secret)
  self._aliases[name] = options[:alias] if options.key?(:alias)
  self._required[name] = options[:required] if options.key?(:required)
  self._deprecated_params[name] = options[:deprecated] if options.key?(:deprecated)
  self._obsoleted_params[name] = options[:obsoleted] if options.key?(:obsoleted)
  self._list[name] = options[:list] if options.key?(:list)
  self._value_types[name] = options[:value_types] if options.key?(:value_types)
  self._symbolize_keys = options[:symbolize_keys] if options.key?(:symbolize_keys)
end

#config_section(name, **options, &block) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/models/concerns/fluentd/setting/configurable.rb', line 85

def config_section(name, **options, &block)
  if self._sections.key?(name)
    self._sections[name].merge(**options, &block)
  else
    attribute(name, :section)
    section_class = Class.new(::Fluentd::Setting::Section)
    section_class.section_name = name
    section_class.required = options[:required]
    section_class.multi = options[:multi]
    section_class.alias = options[:alias]
    section_class._block = block
    self.const_set(name.to_s.classify, section_class)
    self._sections[name] = section_class
  end
end

#set_argument_name(name) ⇒ Object



106
107
108
# File 'app/models/concerns/fluentd/setting/configurable.rb', line 106

def set_argument_name(name)
  self._argument_name = name
end