Skip to content

Commit

Permalink
OjOptions: Remove needless prefix of constants
Browse files Browse the repository at this point in the history
Signed-off-by: Takuro Ashie <[email protected]>
  • Loading branch information
ashie committed Jul 8, 2021
1 parent d9968a3 commit 54e0cc2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions lib/fluent/oj_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@

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

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

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

def initialize
@options = {}
OJ_OPTIONS_DEFAULTS.each { |key, value| @options[key] = value }
DEFAULTS.each { |key, value| @options[key] = value }
end

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

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

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

@options[key.to_sym] = cast_value
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_oj_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class OjOptionsTest < ::Test::Unit::TestCase
sub_test_case "OjOptions" do
test "when no env vars set, returns default options" do
ENV.delete_if { |key| key.start_with?("FLUENT_OJ_OPTION_") }
assert_equal Fluent::OjOptions::OJ_OPTIONS_DEFAULTS, @oj.get_options
assert_equal Fluent::OjOptions::DEFAULTS, @oj.get_options
end

test "valid env var passed with valid value, default is overridden" do
Expand Down

0 comments on commit 54e0cc2

Please sign in to comment.