palkan/anyway_config

Writer receives JSON from environment variable as array of strings, not a string

RB-Lab opened this issue · 1 comments

What did you do?

I have a .env file that has JSON in it:

FOO_BAR='{"baz":"fizz","baz2":"fizz2","baz3":"fizz3"}'

And a config:

class Config < Anyway::Config
  attr_config :bar
  env_prefix :foo
  def bar=(val)
    super JSON.parse(val)
  end
end

What did you expect to happen?

I expected that config.bar would be a hash {baz: "fizz", baz2: "fizz2", baz3: "fizz3"}

What actually happened?

I've got an error no implicit conversion of Array into String.

Additional context

When I've put puts val into writer, it printed something like

{"baz":  "fizz"
baz2":  "fizz2
"baz3":  "fizz3"}

Actually I've got the whole thing working with

  def bar=(val)
    super JSON.parse(val.join('","').gsub('""', '"'))
  end

But that looks aweful.

Environment

Ruby Version:
ruby 2.7.1p83

Framework Version (Rails, whatever):
none (custom)

Anyway Config Version:
anyway_config (2.0.5)

The bug is reproducible on the current version of gem on Rails.