Module: Fluentd::Setting::Configurable

Extended by:
ActiveSupport::Concern
Included in:
Plugin, PluginParameter
Defined in:
app/models/concerns/fluentd/setting/configurable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#initialize(attributes = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/concerns/fluentd/setting/configurable.rb', line 28

def initialize(attributes = {})
  # the superclass does not know specific attributes of the model
  begin
    super
  rescue ActiveModel::UnknownAttributeError => ex
    Rails.logger.warn(ex)
  end
  self.class._sections.each do |name, klass|
    klass.init
    if klass.multi
      next if attributes.nil?
      next if attributes[name].nil?
      attributes[name].each do |attr|
        next unless attr
        attr.each do |index, _attr|
          self._section_params[name] << klass.new(_attr)
        end
      end
    else
      attr = attributes.dig(name, "0")
      self._section_params[name] << klass.new(attr) if attr
    end
  end
end