Class: Fastball::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/fastball/config.rb

Overview

The Fastball::Config generates environment specific configuration files.

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,

---
<%= staging %>:
  adapter: mysql2
  host: <%= db.host %>
  username: <%= db.username %>
  password: <%= db.password %>

and save the following config values to app_config.yml.

---
db:
  host: localhost
  username: dbuser
  password: secret

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config


73
74
75
# File 'lib/fastball/config.rb', line 73

def config
  @config
end

Class Method Details

.generateObject

See Fastball::Config for information about .generate.


80
81
82
# File 'lib/fastball/config.rb', line 80

def generate
  self.new.generate
end

Instance Method Details

#generateObject

See Fastball::Config for information about #generate.


86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/fastball/config.rb', line 86

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