Sha256: 318e7f4dc07edca7a2d629472c767676392190a411e975b2ce2397954a112913

Contents?: true

Size: 1.23 KB

Versions: 45

Compression:

Stored size: 1.23 KB

Contents

require 'fluent/config/types'

module Fluent
  class OjOptions
    OPTIONS = {
      'bigdecimal_load': :symbol,
      'mode': :symbol,
      'use_to_json': :bool
    }

    ALLOWED_VALUES = {
      'bigdecimal_load': %i[bigdecimal float auto],
      'mode': %i[strict null compat json rails custom]
    }

    DEFAULTS = {
      'bigdecimal_load': :float,
      'mode': :compat,
      'use_to_json': true
    }

    @@available = false

    def self.available?
      @@available
    end

    def self.load_env
      options = self.get_options
      begin
        require 'oj'
        Oj.default_options = options
        @@available = true
      rescue LoadError
        @@available = false
      end
      options
    end

    private

    def self.get_options
      options = {}
      DEFAULTS.each { |key, value| options[key] = value }

      OPTIONS.each do |key, type|
        env_value = ENV["FLUENT_OJ_OPTION_#{key.upcase}"]
        next if env_value.nil?

        cast_value = Fluent::Config.reformatted_value(OPTIONS[key], env_value, { strict: true })
        next if cast_value.nil?

        next if ALLOWED_VALUES[key] && !ALLOWED_VALUES[key].include?(cast_value)

        options[key.to_sym] = cast_value
      end

      options
    end
  end
end

Version data entries

45 entries across 45 versions & 6 rubygems

Version Path
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/lib/fluent/oj_options.rb
fluentd-1.16.6-x86-mingw32 lib/fluent/oj_options.rb
fluentd-1.16.6-x64-mingw32 lib/fluent/oj_options.rb
fluentd-1.16.6-x64-mingw-ucrt lib/fluent/oj_options.rb
fluentd-1.16.6 lib/fluent/oj_options.rb
fluentd-1.17.1-x86-mingw32 lib/fluent/oj_options.rb
fluentd-1.17.1-x64-mingw32 lib/fluent/oj_options.rb
fluentd-1.17.1-x64-mingw-ucrt lib/fluent/oj_options.rb
fluentd-1.17.1 lib/fluent/oj_options.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/lib/fluent/oj_options.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/lib/fluent/oj_options.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/lib/fluent/oj_options.rb
fluentd-1.17.0-x86-mingw32 lib/fluent/oj_options.rb
fluentd-1.17.0-x64-mingw-ucrt lib/fluent/oj_options.rb
fluentd-1.17.0-x64-mingw32 lib/fluent/oj_options.rb
fluentd-1.17.0 lib/fluent/oj_options.rb
fluentd-1.16.5-x64-mingw-ucrt lib/fluent/oj_options.rb
fluentd-1.16.5-x86-mingw32 lib/fluent/oj_options.rb
fluentd-1.16.5-x64-mingw32 lib/fluent/oj_options.rb
fluentd-1.16.5 lib/fluent/oj_options.rb