Closed RB-Lab closed 2 years ago
I have a .env file that has JSON in it:
.env
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
I expected that config.bar would be a hash {baz: "fizz", baz2: "fizz2", baz3: "fizz3"}
config.bar
{baz: "fizz", baz2: "fizz2", baz3: "fizz3"}
I've got an error no implicit conversion of Array into String.
no implicit conversion of Array into String
When I've put puts val into writer, it printed something like
puts val
{"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.
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.
What did you do?
I have a
.env
file that has JSON in it:And a config:
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 likeActually I've got the whole thing working with
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)