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

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

Backend Configuration collapse

Instance Method Details

#apply_plugin(name) ⇒ Object

Apply custom processing for plugin


115
116
117
118
119
120
121
122
# File 'lib/mobility/backends/key_value.rb', line 115

def apply_plugin(name)
  if name == :cache
    include self::Cache
    true
  else
    super
  end
end

#configure(options) ⇒ Object

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • type (Symbol, String)

    Column type to use

  • associaiton_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


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

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]))
    # TODO: Remove warning and raise ArgumentError in v1.0
    warn %{
WARNING: In previous versions, the Mobility KeyValue backend defaulted to a
text type column, but this behavior is now deprecated and will be removed in
the next release. Either explicitly specify the type by passing type: :text in
each translated model, or set a default option in your configuration.
  }
    options[:type] = :text
  end
end

#table_alias(attr, locale) ⇒ Object


124
125
126
# File 'lib/mobility/backends/key_value.rb', line 124

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