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



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/mobility/backends/key_value.rb', line 100

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])
  options[:key_column]       ||= :key
  options[:value_column]     ||= :value
  options[:belongs_to]       ||= :translatable
  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



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

def include_cache
  include self::Cache
end

#table_alias(attr, locale) ⇒ Object



117
118
119
# File 'lib/mobility/backends/key_value.rb', line 117

def table_alias(attr, locale)
  "#{model_class}_#{attr}_#{Mobility.normalize_locale(locale)}_#{options[:association_name]}"
end

#valid_keysObject



88
89
90
# File 'lib/mobility/backends/key_value.rb', line 88

def valid_keys
  [:type, :association_name, :class_name, :key_column, :value_column, :belongs_to]
end