Module: Globalize::ActiveRecord::ActMacro

Defined in:
lib/globalize/active_record/act_macro.rb

Instance Method Summary collapse

Instance Method Details

#class_nameObject



27
28
29
30
# File 'lib/globalize/active_record/act_macro.rb', line 27

def class_name
  class_name = table_name[table_name_prefix.length..-(table_name_suffix.length + 1)].downcase.camelize
  pluralize_table_names ? class_name.singularize : class_name
end

#translates(*attr_names) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/globalize/active_record/act_macro.rb', line 4

def translates(*attr_names)
  return if translates?

  options = attr_names.extract_options!
  options[:table_name] ||= "#{table_name.singularize}_translations"

  class_inheritable_accessor :translated_attribute_names, :translation_options
  self.translated_attribute_names = attr_names.map(&:to_sym)
  self.translation_options        = options

  include InstanceMethods
  extend  ClassMethods, Migration

  has_many :translations, :class_name  => translation_class.name,
                          :foreign_key => class_name.foreign_key,
                          :dependent   => :delete_all,
                          :extend      => HasManyExtensions

  after_save :save_translations!

  attr_names.each { |attr_name| translated_attr_accessor(attr_name) }
end

#translates?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/globalize/active_record/act_macro.rb', line 32

def translates?
  included_modules.include?(InstanceMethods)
end