module Mobility::Backend

Defines a minimum set of shared components included in any backend. These are:

On top of this, a backend will normally:

@example Defining a Backend

class MyBackend
  include Mobility::Backend

  def read(locale, options = {})
    # ...
  end

  def write(locale, value, options = {})
    # ...
  end

  def each_locale
    # ...
  end

  def self.configure(options)
    # ...
  end

  setup do |attributes, options|
    # Do something with attributes and options in context of model class.
  end
end

@see Mobility::Translations

Constants

Translation

Attributes

attribute[R]

@return [String] Backend attribute

model[R]

@return [Object] Model on which backend is defined

Public Class Methods

included(base) click to toggle source

Extend included class with setup method and other class methods

# File lib/mobility/backend.rb, line 118
def self.included(base)
  base.extend ClassMethods
  base.singleton_class.attr_reader :options, :model_class
end
new(*args) click to toggle source

@!macro [new] backend_constructor

@param model Model on which backend is defined
@param [String] attribute Backend attribute
# File lib/mobility/backend.rb, line 68
def initialize(*args)
  @model = args[0]
  @attribute = args[1]
end

Public Instance Methods

each() { |translation| ... } click to toggle source

Yields translations to block @yieldparam [Mobility::Backend::Translation] Translation

# File lib/mobility/backend.rb, line 92
def each
  each_locale { |locale| yield Translation.new(self, locale) }
end
each_locale() click to toggle source

@!macro [new] backend_iterator

Yields locales available for this attribute.
@yieldparam [Symbol] Locale
# File lib/mobility/backend.rb, line 87
def each_locale
end
locales() click to toggle source

List locales available for this backend. @return [Array<Symbol>] Array of available locales

# File lib/mobility/backend.rb, line 98
def locales
  map(&:locale)
end
options() click to toggle source

@return [Hash] options

# File lib/mobility/backend.rb, line 113
def options
  self.class.options
end
present?(locale, options = {}) click to toggle source

@param [Symbol] locale Locale to read @return [TrueClass,FalseClass] Whether translation is present for locale

# File lib/mobility/backend.rb, line 104
def present?(locale, options = {})
  Util.present?(read(locale, **options))
end