-
Define predicate methods when
:boolean
type is specified for the attribute. (@palkan) -
Add support for nested required config attributes. (@palkan)
The API is inspired by Rails permitted params:
class AppConfig < Anyway::Config
attr_config :assets_host, database: {host: nil, port: nil}
required :assets_host, database: [:host, :port]
end
- Add support for using
env_prefix ""
to load from unprefixed env vars. (@palkan)
See #118.
-
Added EJSON support. (@inner-whisper)
-
Add Doppler loader. (@prog-supdex).
-
[Fixes #110] Fix setting up autoloader for the same folder. (@palkan)
-
RBS: Now
.on_load
automatically pass block context type (instance), so no need to add annotations! (@palkan)
Steep 1.2+ is required. Read more about the feature.
- Added
manifest.yml
for RBS. (@palkan)
- Add ability to load configurations under specific environments in pure Ruby apps. (@fargelus).
Before loading environment configurations you need to specify variable Anyway::Settings.current_environment
. In Rails apps this variable is same as Rails.env
value.
After adding yaml loader will try to load params under this environment.
Also required env option was added to Anyway::Config
.
-
Fix Ruby 3.1 compatibility. (@palkan)
-
Add ability to set default key for environmental YAML files. (@skryukov)
Define a key for environmental yaml files to read default values from with config.anyway_config.default_environmental_key = "default"
.
This way Anyway Config will try to read settings under the "default"
key and then merge environmental settings into them.
- Fixed regression introduced by the
#deep_merge!
refinement.
- Minor fixes to the prev release.
- Add RBS signatures and generator. (@palkan)
Anyway Config now ships with the basic RBS support. To use config types with Steep, add library "anyway_config"
to your Steepfile.
We also provide an API to generate a signature for you config class: MyConfig.to_rbs
. You can use this method to generate a scaffold for your config class.
- Add type coercion support. (@palkan)
Example:
class CoolConfig < Anyway::Config
attr_config :port, :user
coerce_types port: :string, user: {dob: :date}
end
ENV["COOL_USER__DOB"] = "1989-07-01"
config = CoolConfig.new({port: 8080})
config.port == "8080" #=> true
config.user["dob"] == Date.new(1989, 7, 1) #=> true
You can also add .disable_auto_cast!
to your config class to disable automatic conversion.
Warning Now values from all sources are coerced (e.g., YAML files). That could lead to a different behaviour.
-
Do not dup modules/classes passed as configuration values. (@palkan)
-
Handle loading empty YAML config files. ([@micahlee][])
- Drop deprecated
attr_config
instance variables support.
Config setters no longer write instance variables.
- Add
config.anyway_config.future
to allow enabling upcoming features. (@palkan)
For smoother upgrades, we provide a mechanism to opt-out to the new defaults beforehand.
Currently, only :unwrap_known_environments
feature could be enabled (see below):
config.anyway_config.future.use :unwrap_known_environments
-
Allow to skip environment keys completely (e.g.,
development:
,test:
) in a config YML when used with Rails. In that case same config is loaded in all known environments (same mechanism as for non-Rails applications) -
Add the
known_environments
property to Anyway::Settings under Rails. Useconfig.anyway_config.known_environments << "staging"
to make the gem aware of custom environments. (@progapandist) -
Make it possible to specify default YML configs directory. (@palkan)
For example:
Anyway::Settings.default_config_path = "path/to/configs"
# or in Rails
config.anyway_config.default_config_path = Rails.root.join("my/configs")
- Fix Ruby 2.7 warnings. (@palkan)
- Use
YAML.load
instead ofYAML.safe_laad
. (@palkan)
- Fix regression with adding
ruby-next
as a runtime dependency even for RubyGems release. (@palkan)
- Enable auto-transpiling to allow installing from source. (@palkan)
- Make sure configs are eager loaded in Rails when
config.eager_load = true
. (@palkan)
Fixes #58.
- Fix loading Railtie when application has been already initialized. (@palkan)
Fixes #56.
- Fix double
yield
in tracing for ENV loader. (@Envek)
- Add predicate methods for attributes with boolean defaults. (@palkan)
For example:
class MyConfig < Anyway::Config
attr_config :key, :secret, debug: false
end
MyConfig.new.debug? #=> false
MyConfig.new(debug: true).debug? #=> true
- Add
Config#deconstruct_keys
. (@palkan)
Now you can use configs in pattern matching:
case AWSConfig.new
in bucket:, region: "eu-west-1"
setup_eu_storage(bucket)
in bucket:, region: "us-east-1"
setup_us_storage(bucket)
end
- Add pretty_print support. (@palkan)
Whenever you use pp
, the output would contain pretty formatted config information
including the sources.
Example:
pp CoolConfig.new
# #<CoolConfig
# config_name="cool"
# env_prefix="COOL"
# values:
# port => 3334 (type=load),
# host => "test.host" (type=yml path=./config/cool.yml),
# user =>
# name => "john" (type=env key=COOL_USER__NAME),
# password => "root" (type=yml path=./config/cool.yml)>
- Add source tracing support. (@palkan)
You can get the information on where a particular parameter value came from
(which loader) through via #to_source_trace
method:
conf = MyConfig.new
conf.to_source_trace
# {
# "host" => {value: "test.host", source: {type: :user, called_from: "/rails/root/config/application.rb:21"}},
# "user" => {
# "name" => {value: "john", source: {type: :env, key: "COOL_USER__NAME"}},
# "password" => {value: "root", source: {type: :yml, path: "config/cool.yml"}}
# },
# "port" => {value: 9292, source: {type: :defaults}}
# }
- Change the way Rails configs autoloading works. (@palkan)
In Rails 6, autoloading before initialization is deprecated. We can still make it work by using our own autoloading mechanism (custom Zeitwerk loader).
This forces us to use a custom directory (not app/
) for configs required at the boot time.
By default, we put static configs into config/configs
but you can still use app/configs
for
dynamic (runtime) configs.
NOTE: if you used app/configs
with 2.0.0.preX and relied on configs during initialization,
you can set static configs path to app/configs
:
config.anyway_config.autoload_static_config_path = "app/configs"
You can do this by running the generator:
rails g anyway:install --configs-path=app/configs
- Add Rails generators. (@palkan)
You can create config classes with the predefined attributes like this:
rails generate config aws access_key_id secret_access_key region
- BREAKING The accessors generated by
attr_config
are not longerattr_accessor
-s. (@palkan)
You cannot rely on instance variables anymore. Instead, you can use super
when overriding accessors or
values[name]
:
attr_config :host, :port, :url, :meta
# override writer to handle type coercion
def meta=(val)
super JSON.parse(val)
end
# or override reader to handle missing values
def url
values[:url] ||= "#{host}:#{port}"
end
# in <2.1 it's still possible to read instance variables,
# i.e. the following would also work
def url
@url ||= "#{host}:#{port}"
end
NOTE: we still set instance variables in writers (for backward compatibility), but that would be removed in 2.1.
describe_options(
concurrency: {
desc: "number of threads to use",
type: String
}
)
- Add param presence validation. (@palkan)
You can specify some params as required, and the validation error would be raised if they're missing or empty (only for strings):
class MyConfig < Anyway::Config
attr_config :api_key, :api_secret, :debug
required :api_key, :api_secret
end
MyConfig.new(api_secret: "") #=> raises Anyway::Config::ValidationError
You can change the validation behaviour by overriding the #validate!
method in your config class.
- Validate config attribute names. (@palkan)
Do not allow using reserved names (Anyway::Config
method names).
Allow only alphanumeric names (matching /^[a-z_]([\w]+)?$/
).
- Add Loaders API. (@palkan)
All config sources have standardized via loaders API. It's possible to define custom loaders or change the sources order.
- Fix bug with loading from credentials when local credentials are missing. (@palkan)
- BREAKING Changed the way of providing explicit values. (@palkan)
# BEFORE
Config.new(overrides: data)
# AFTER
Config.new(data)
- Add Railtie. (@palkan)
Anyway::Railtie
provides Anyway::Settings
access via Rails.applicaiton.configuration.anyway_config
.
It also adds app/configs
path to autoload paths (low-level, ActiveSupport::Dependencies
) to
make it possible to use configs in the app configuration files.
- Add test helpers. (@palkan)
Added with_env
helper to test code in the context of the specified
environment variables.
Included automatically in RSpec for examples with the type: :config
meta
or with the spec/configs
path.
- Add support for local files. (@palkan)
Now users can store their personal configurations in local files:
<config_name>.local.yml
config/credentials/local.yml.enc
(for Rails 6).
Local configs are meant for using in development and only loaded if
Anyway::Settings.use_local_files
is true
(which is true by default if
RACK_ENV
or RAILS_ENV
env variable is equal to "development"
).
- Add Rails credentials support. (@palkan)
The data from credentials is loaded after the data from YAML config and secrets, but before environmental variables (i.e. env variables are stronger)
- Update config name inference logic. (@palkan)
Config name is automatically inferred only if:
-
the class name has a form of
<Module>::Config
(SomeModule::Config => "some_module"
) -
the class name has a form of
<Something>Config
(SomeConfig => "some"
) -
Fix config classes inheritance. (@palkan)
Previously, inheritance didn't work due to the lack of proper handling of class-level configuration (naming, option parses settings, defaults).
Now it's possible to extend config classes without breaking the original classes functionality.
- Require Ruby >= 2.5.0.
- Fix: detect Rails by presence of
Rails::VERSION
(instead of justRails
). (@palkan)
- Add
.flag_options
to mark some params as flags (value-less) for OptionParse. (@palkan)
- Add OptionParse integration (@jastkand)
See more PR#18.
- Use underscored config name as an env prefix. (@palkan)
For a config class:
class MyApp < Anyway::Config
end
Before this change we use MYAPP_
prefix, now it's MY_APP_
.
You can specify the prefix explicitly:
class MyApp < Anyway::Config
env_prefix "MYAPP_"
end
-
Ruby 2.2 is no longer supported.
-
Anyway::Config.env_prefix
method is introduced. (@charlie-wasp)
Now works on JRuby 9.1+.
- Allow to pass raw hash with explicit values to
Config.new
. (@dsalahutdinov)
Example:
Sniffer::Config.new(
overrides: {
enabled: true,
storage: {capacity: 500}
}
)
See more PR#10.
- Enable aliases for YAML. (@onemanstartup)
- Return deep duplicate of a Hash in
Env#fetch
. (@palkan)
- Add
#to_h
method. (@palkan)
See #4.
- Make it possible to extend configuration parameters. (@palkan)
-
Lazy load and parse ENV configuration. (@palkan)
-
Add support for ERB in YML configuration. (@palkan)
- Drop
active_support
dependency. (@palkan)
Use custom refinements instead of requiring active_support
.
No we're dependency-free!
- Initial version.