Module: Globalize::ActiveRecord::ActMacro

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

Instance Method Summary collapse

Instance Method Details

#class_nameObject


40
41
42
43
44
45
# File 'lib/globalize/active_record/act_macro.rb', line 40

def class_name
  @class_name ||= begin
    class_name = table_name[table_name_prefix.length..-(table_name_suffix.length + 1)].downcase.camelize
    pluralize_table_names ? class_name.singularize : class_name
  end
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
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/globalize/active_record/act_macro.rb', line 4

def translates(*attr_names)

  options = attr_names.extract_options!
  setup_translates!(options) unless translates?

  attr_names = attr_names.map(&:to_sym)
  attr_names -= translated_attribute_names if defined?(translated_attribute_names)

  if attr_names.present?
    translation_class.instance_eval %{
      attr_accessible :#{attr_names.join(', :')}
    }

    attr_names.each do |attr_name|
      # Detect and apply serialization.
      serializer = self.serialized_attributes[attr_name.to_s]
      if serializer.present?
        if defined?(::ActiveRecord::Coders::YAMLColumn) &&
           serializer.is_a?(::ActiveRecord::Coders::YAMLColumn)

          serializer = serializer.object_class
        end

        translation_class.send :serialize, attr_name, serializer
      end

      # Create accessors for the attribute.
      translated_attr_accessor(attr_name)
      translations_accessor(attr_name)

      # Add attribute to the list.
      self.translated_attribute_names << attr_name
    end
  end
end

#translates?Boolean

Returns:

  • (Boolean)

47
48
49
# File 'lib/globalize/active_record/act_macro.rb', line 47

def translates?
  included_modules.include?(InstanceMethods)
end