-
Notifications
You must be signed in to change notification settings - Fork 87
Introduction to Mobility v1.0
This page documents changes (mostly in configuration) between the latest 0.8 release and 1.0.
If you just want to update to 1.0 from an earlier version, update your Mobility.configure
code to look like the one in the new initializer template.
Previously, Mobility had a Mobility::Configuration
class with settings such as default_backend
, accessor_method
and query_method
. These were global settings which could be accessed from any backend or plugin.
Similarly, while plugins existed, they were mostly implicitly included (fallbacks, dirty tracking, etc) and could only be "disabled" by passing a falsey value to translates
, e.g. dirty: false
. While this disabled them, the plugin was still present.
With 1.0, everything is centralized around plugins, none of which are included unless you ask for them. (This means that specs can also test conditions in complete isolation.)
So while the syntax looks similar, when you now call:
Mobility.configure do |config|
# ...
the config
here is not a "Configuration" but an instance of Mobility::Pluggable
, with some methods to declare and customize plugins. You call config.plugins
to declare plugins, with optional default settings.
Here is how we would set the default backend to :key_value
and enable fallbacks and dirty tracking:
Mobility.configure do |config|
config.plugins do
backend :key_value
fallbacks
dirty
end
end
Plugins can have dependencies and those dependencies will be resolved inside the plugins
block.
In the same spirit of making things more explicit, Mobility no longer inspects constants to figure out which ORM you're using; instead, you just declare the active_record
or sequel
plugin:
Mobility.configure do |config|
config.plugins do
backend :key_value
active_record # or sequel
# ...
end
end