Module: Mobility::Backends::KeyValue::ClassMethods

Defined in:
lib/mobility/backends/key_value.rb

Backend Configuration collapse

Instance Method Summary collapse

Instance Method Details

#configure(options) ⇒ Object

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • type (Symbol, String)

    Column type to use

  • association_name (Symbol) — default: :<type>_translations

    Name of association method, defaults to <type>_translations

  • class_name (Symbol)

    Translation class, defaults to Mobility::<ORM>::<type>Translation

Raises:

  • (ArgumentError)

    if type is not set, and both class_name and association_name are also not set


98
99
100
101
102
103
104
105
# File 'lib/mobility/backends/key_value.rb', line 98

def configure(options)
  options[:type]             &&= options[:type].to_sym
  options[:association_name] &&= options[:association_name].to_sym
  options[:class_name]       &&= Util.constantize(options[:class_name])
  if !(options[:type] || (options[:class_name] && options[:association_name]))
    raise ArgumentError, "KeyValue backend requires an explicit type option, either text or string."
  end
end

#include_cacheObject

Apply custom processing for cache plugin


108
109
110
# File 'lib/mobility/backends/key_value.rb', line 108

def include_cache
  include self::Cache
end

#table_alias(attr, locale) ⇒ Object


112
113
114
# File 'lib/mobility/backends/key_value.rb', line 112

def table_alias(attr, locale)
  table_alias_affix % "#{attr}_#{Mobility.normalize_locale(locale)}"
end

#valid_keysObject


86
87
88
# File 'lib/mobility/backends/key_value.rb', line 86

def valid_keys
  [:type, :association_name, :class_name]
end