palkan / anyway_config

Configuration library for Ruby gems and applications
MIT License
778 stars 52 forks source link

Config to ENV conversion #124

Closed palkan closed 1 year ago

palkan commented 1 year ago

Is your feature request related to a problem? Please describe.

Make it possible to convert a config instance to the ENV-like hash (which could be merged into ENV or dumped into a file or whatever).

Describe the solution you'd like

Example:

class MyConfig < Anyway::Config
  env_prefix :myconf
  attr_config :host, :port, :user
end

MyConfig.new(host: "localhost", port: 8000, user: {name: "Jack"}).as_env 
#=> 
# {
#   "MYCONF_HOST" => "localhost",
#   "MYCONF_PORT" => "8000",
#   "MYCONF_USER__NAME => "Jack"
# }

Additional context

Based on the discussion: https://github.com/palkan/anyway_config/discussions/116

palkan commented 1 year ago

Added in #125. Released in v2.4.0