Sha256: 008851f8d997b6138f03bf35a304686cd26418f1bdf059431e2b3108443aaeb8
Contents?: true
Size: 1.75 KB
Versions: 5
Compression:
Stored size: 1.75 KB
Contents
module HasManyTranslations # Provides +has_translations+ options conversion and cleanup. module Options def self.included(base) # :nodoc: base.class_eval do extend ClassMethods end end # Class methods that provide preparation of options passed to the +has_translations+ method. module ClassMethods # 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. 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 self.translator.key = HmtSettings.google_api_key end self.has_many_translations_options = options.dup options.merge!( :as => :translated, :extend => Array(options[:extend]).unshift(Translations) ) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems