Module: HasManyTranslations::Options::ClassMethods

Defined in:
lib/has_many_translations/options.rb

Overview

Class methods that provide preparation of options passed to the has_translations method.

Instance Method Summary collapse

Instance Method Details

#prepare_translated_options(options) ⇒ Object

The prepare_has_translations_options method has three purposes:

  1. Populate the provided options with default values where needed

  2. Prepare options for use with the has_many association

  3. Save user-configurable options in a class-level variable

Options are given priority in the following order:

  1. Those passed directly to the translated method

  2. Those specified in an initializer configure block

  3. Default values specified in prepare_has_translations_options

The method is overridden in feature modules that require specific options outside the standard has_many associations.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/has_many_translations/options.rb', line 26

def prepare_translated_options(options)
  options.symbolize_keys!
  options.reverse_merge!(Configuration.options)
  options.reverse_merge!(
    :class_name => 'HasManyTranslations::Translation',
    :dependent => :delete_all
  )
  class_inheritable_accessor :has_many_translations_options
  class_inheritable_accessor :translator
  # self.translator = Translate::RTranslate.new
  if defined? HmtSettings
    ToLang.start(HmtSettings.google_api_key)
    # self.translator.key = HmtSettings.google_api_key
    options[:default_languages] = HmtSettings.default_languages ? HmtSettings.default_languages : nil
    options[:languages] = HmtSettings.languages ? HmtSettings.languages : nil
    # options[:force_on_update] = HmtSettings.force_on_update ? HmtSettings.force_on_update : nil
    
  end
  self.has_many_translations_options = options.dup

  options.merge!(
    :as => :translated,
    :extend => Array(options[:extend]).unshift(Translations)
  )
end