Module: Mobility::Plugins

Defined in:
lib/mobility/plugins.rb,
lib/mobility/plugins/cache.rb,
lib/mobility/plugins/dirty.rb,
lib/mobility/plugins/sequel.rb,
lib/mobility/plugins/default.rb,
lib/mobility/plugins/presence.rb,
lib/mobility/plugins/fallbacks.rb,
lib/mobility/plugins/active_model.rb,
lib/mobility/plugins/sequel/dirty.rb,
lib/mobility/plugins/active_record.rb,
lib/mobility/plugins/locale_accessors.rb,
lib/mobility/plugins/active_model/dirty.rb,
lib/mobility/plugins/active_record/dirty.rb,
lib/mobility/plugins/fallthrough_accessors.rb,
lib/mobility/plugins/cache/translation_cacher.rb

Overview

Plugins allow modular customization of backends independent of the backend itself. They are enabled through the Configuration#plugins configuration setting, which takes an array of symbols corresponding to plugin names. The order of these names is important since it determines the order in which plugins will be applied.

So if our Configuration#plugins is an array [:foo], and we call ‘translates` on our model, Post, like this:

class Post
  translates :title, foo: true
end

Then the Foo plugin will be applied with the option value true. Applying a module calls a class method, apply (in this case Foo.apply), which takes two arguments:

  • an instance of the Attributes class, attributes, from which the backend can configure the backend class (attributes.backend_class) and the model (attributes.model_class), and the attributes module itself (which will be included into the backend).

  • the value of the option passed into the model with translates (in this case, true).

Typically, the plugin will include a module into either attributes.backend_class or attributes itself, configured according to the option value. For examples, see classes under the Plugins namespace.

Defined Under Namespace

Modules: ActiveModel, ActiveRecord, Cache, Dirty, Presence, Sequel Classes: Default, Fallbacks, FallthroughAccessors, LocaleAccessors