Module: Fluentd::Setting::PluginParameter::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#_permit_section(key, section) ⇒ Object



147
148
149
150
151
152
153
# File 'app/models/concerns/fluentd/setting/plugin_parameter.rb', line 147

def _permit_section(key, section)
  keys = { key => section._types.keys }
  section._sections.each do |_key, _section|
    keys[key] << _permit_section(_key, _section)
  end
  keys
end

#column_type(name) ⇒ Object



81
82
83
# File 'app/models/concerns/fluentd/setting/plugin_parameter.rb', line 81

def column_type(name)
  self._types[name]
end

#default(name) ⇒ Object



93
94
95
# File 'app/models/concerns/fluentd/setting/plugin_parameter.rb', line 93

def default(name)
  reformat_value(name, self._defaults[name])
end

#desc(name) ⇒ Object



89
90
91
# File 'app/models/concerns/fluentd/setting/plugin_parameter.rb', line 89

def desc(name)
  self._descriptions[name]
end

#have_buffer_section?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'app/models/concerns/fluentd/setting/plugin_parameter.rb', line 97

def have_buffer_section?
  self._sections.key?(:buffer)
end

#have_format_section?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'app/models/concerns/fluentd/setting/plugin_parameter.rb', line 109

def have_format_section?
  self._sections.key?(:format)
end

#have_parse_section?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'app/models/concerns/fluentd/setting/plugin_parameter.rb', line 105

def have_parse_section?
  self._sections.key?(:parse)
end

#have_storage_section?Boolean

Returns:

  • (Boolean)


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

def have_storage_section?
  self._sections.key?(:storage)
end

#initial_paramsObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/models/concerns/fluentd/setting/plugin_parameter.rb', line 113

def initial_params
  new # ensure to load attributes
  params = {}
  self._defaults.each do |key, value|
    if key.to_s.start_with?("@")
      params[key.to_s[1..-1].to_sym] = value
    else
      params[key] = value
    end
  end
  self._sections.each do |key, section|
    next if section.initial_params.blank?
    params[key] = {
      "0" => section.initial_params.stringify_keys
    }
  end
  params
end

#list_of(name) ⇒ Object



85
86
87
# File 'app/models/concerns/fluentd/setting/plugin_parameter.rb', line 85

def list_of(name)
  self._list[name]
end

#permit_paramsObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'app/models/concerns/fluentd/setting/plugin_parameter.rb', line 132

def permit_params
  self.new # init
  keys = self._types.keys
  self._sections.each do |key, section|
    keys << _permit_section(key, section)
  end

  keys << :buffer_type if have_buffer_section?
  keys << :storage_type if have_storage_section?
  keys << :parse_type if have_parse_section?
  keys << :format_type if have_format_section?

  keys
end

#reformat_value(name, value) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'app/models/concerns/fluentd/setting/plugin_parameter.rb', line 155

def reformat_value(name, value)
  type = column_type(name)
  return value if type.nil? # name == :time_key
  return value.to_sym if type == :enum
  return value if type == :regexp
  type_name = if type.is_a?(Fluentd::Setting::Type::Time)
                :time
              else
                type
              end
  begin
    Fluent::Config::REFORMAT_VALUE.call(type_name, value.dup)
  rescue TypeError
    Fluent::Config::REFORMAT_VALUE.call(type_name, value)
  end
end