Skip to content

Introduction to Mobility v1.0

Chris Salzberg edited this page Oct 25, 2020 · 16 revisions

This page documents changes (mostly in configuration) between the latest 0.8 release and 1.0.

TL;DR

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.

What changed

Configuration

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.

ORM plugin must be explicitly enabled

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