module Translatable::ActiveRecord::ClassMethods
Protected Instance Methods
reflection_locale()
click to toggle source
# File lib/translatable/orm/active_record.rb, line 112 def reflection_locale @translatable_base.locale_column end
t_register_locale()
click to toggle source
# File lib/translatable/orm/active_record.rb, line 102 def t_register_locale @translatable_base.mapping.each_pair do |attr, attr_alias| self.instance_eval do define_method attr_alias do current_translation.try(attr) end end end end
t_register_origin()
click to toggle source
Handle the routine to define all th required stuff on the original maodel
# File lib/translatable/orm/active_record.rb, line 72 def t_register_origin has_many :translations, :class_name => @translatable_base.translation_model.to_s, :foreign_key => @translatable_base.origin_key, :inverse_of => @translatable_base.or_name, :dependent => :destroy class_eval <<-EOS has_one :current_translation, -> { where("#{reflection_locale}" => ::I18n.locale) }, :class_name => @translatable_base.translation_model.to_s, :foreign_key => @translatable_base.origin_key EOS end
t_register_translations()
click to toggle source
# File lib/translatable/orm/active_record.rb, line 86 def t_register_translations @translatable_base.tap do |t| t.t_model.validates t.locale_column, :presence => true t.t_model.validates t.locale_column, :uniqueness => { :scope => t.origin_key } t.t_model.validates t.locale_column, :format => {:with => /[a-z]{2}/}, :unless => Proc.new { |record| record.public_send(t.locale_column).blank? } t.t_model.belongs_to t.or_name, :class_name => self.name, :inverse_of => :translations t.fields.each do |f| t.t_model.validates(f.first, f.last) unless f[1].blank? end end end