Class: Fastball::Config
- Inherits:
-
Object
- Object
- Fastball::Config
- Extended by:
- Forwardable
- Defined in:
- lib/fastball/config.rb
Overview
The Fastball::Config generates environment specific configuration files.
usage
Set up your application’s configuration templates and app_config.yml file as described below, then run the following rake task:
`rake fastball:config`
Conventions
Fastball looks for ERB configuration templates in the following locations relative to the current working directory:
- .env.erb
- config/*.erb
The generated config files will have the same path as the config templates but with the .erb extension removed.
config/database.yml.erb --> rake fastball:config --> config/database.yml
You should never edit the generated config file by hand because Fastball will overwrite your changes.
app_config.yml
To customize the configuration for a specific environment, Fastball expects to find an app_config.yml file in the current directory containing the environment specific values for the variables refenced in the config templates. Fastball will complain if this file does not exist or is missing a config value required by one of the templates.
Fastball does not generate app_config.yml for you. Typically, your configuration management tool (ansible, chef, puppet, etc.) will generate app_config.yml for deployment environments, and developers will create and edit app_config.yml locally. It is recommended that you don’t commit this file to version control. Instead, you should create an app_config.yml.example with dummy config values to use in development/test environments that other team members can copy to app_config.yml and modify for their specific environment.
Example
To generate the following config/database.yml file,
---
staging:
adapter: mysql2
host: localhost
username: dbuser
password: secret
you would create a config/database.yml.erb template like this,
---
<%= rails_env %>:
adapter: mysql2
host: <%= db.host %>
username: <%= db.username %>
password: <%= db.password %>
and save the following config values to app_config.yml.
---
rails_env: staging
db:
host: localhost
username: dbuser
password: secret
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
-
.generate ⇒ Object
See Config for information about
.generate.
Instance Method Summary collapse
-
#generate ⇒ Object
See Config for information about
#generate.
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
82 83 84 |
# File 'lib/fastball/config.rb', line 82 def config @config end |
Class Method Details
.generate ⇒ Object
See Fastball::Config for information about .generate.
89 90 91 |
# File 'lib/fastball/config.rb', line 89 def generate self.new.generate end |
Instance Method Details
#generate ⇒ Object
See Fastball::Config for information about #generate.
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/fastball/config.rb', line 95 def generate load_config_values headline "Rendering config files from provided templates.\n" results = template_paths.map do |path| render_template path end headline "Saving new config files.\n" template_paths.zip(results) do |path, result| save_result path, result end end |