module Translator::Translates::ClassMethods

Public Instance Methods

prefixed_attributes() click to toggle source
# File lib/translator/translates.rb, line 59
def prefixed_attributes
  @prefixed_attributes ||= translated_attributes.map{ |a| Translator.prefixed(a) }.flatten
end
translated_attributes() click to toggle source
# File lib/translator/translates.rb, line 55
def translated_attributes
  @translated_attributes ||= []
end
translates(*args) click to toggle source
# File lib/translator/translates.rb, line 43
def translates *args
  self.translated_attributes = args
  self.translated_attributes.each do |name|
    translated_attr_accessor name
    translations_attr_accessor name
  end
end
translates?(name) click to toggle source
# File lib/translator/translates.rb, line 51
def translates? name
  self.translated_attributes.include? name
end

Protected Instance Methods

translated_attr_accessor(name) click to toggle source
# File lib/translator/translates.rb, line 69
def translated_attr_accessor name
  serialize name, ActiveRecord::Coders::Hstore

  attr_accessible *prefixed_attributes

  define_method("#{name}")  { |locale=nil| translated name, locale || I18n.locale }
  define_method("#{name}=") { |value|      translate  name, I18n.locale => value }

  Translator.prefixed_locales.each do |locale|
    define_method("#{locale}_#{name}")  { translated name, locale }
    define_method("#{locale}_#{name}=") { |value| translate name, locale => value }
  end
end
translated_attributes=(value) click to toggle source
# File lib/translator/translates.rb, line 65
def translated_attributes= value
  @translated_attributes = value
end
translations_attr_accessor(name) click to toggle source
# File lib/translator/translates.rb, line 83
def translations_attr_accessor name
  define_method("#{name}_translations")  { read_attribute name }
  define_method("#{name}_translations=") { |value| write_attribute name, value }
end