-
Notifications
You must be signed in to change notification settings - Fork 1
Checking Configuration File Versions
Aaron Bach edited this page May 4, 2014
·
2 revisions
Often, you'll want to check the user's current version of your app against the last version that required some sort of configuration change; moreover, you'll want to run some "re-configuration" steps if the user's version is older than the last version that required a configuration update.
The Configurator
allows for this via its compare_version
method.
Assume you have a config file that looks like this:
---
app_data:
# The current version of the app
APP_VERSION: 0.8.8
# ...other keys...
...and that, somewhere in your app, you store a constant that contains the config version that requires a re-configuration:
LATEST_CONFIG_VERSION = 0.9.5
...this will initiate a version check (and give you the option to do something with that information):
# Store the current version of your app in a
# property of the Configurator.
configuration.current_version = configuration.app_data['APP_VERSION']
# Store the last version of your app that required
# a re-configuration in a property of the Configurator.
configuration.last_version = LATEST_CONFIG_VERSION
# Run the check. If the current version is older than
# the "last" version, use a block to tell the Configurator
# what to do.
configuration.compare_version do |c, l|
puts "We need to update from #{c} to #{l}..."
# ...do stuff...
end
Two items to note:
- If the
current_version
parameter isnil
, the Configurator will assume that it the app needs to be updated whencompare_version
is run. - If the current version is later than the last version that required re-configuration, the whole block is skipped over (allowing your app to get on with its day).