Module: Translatable::ActiveRecord::Macro

Defined in:
lib/translatable/active_record/macro.rb

Instance Method Summary collapse

Instance Method Details

#class_nameObject



37
38
39
40
41
42
# File 'lib/translatable/active_record/macro.rb', line 37

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

#translatable(*attr_names) ⇒ Object



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
# File 'lib/translatable/active_record/macro.rb', line 5

def translatable(*attr_names)

  options = attr_names.extract_options!
  setup_translatable!(options) unless translatable?

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

  if attr_names.present?

    attr_names.each do |attr_name|
      # 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
      if options[:only]
        self.translated_serialized_attributes[attr_name] = options[:only] ? options[:only] : []
      end
    end

    on_after_save_callback(attr_names, options[:after_save]) if options[:after_save]
    on_before_save_callback(attr_names, options[:before_save]) if options[:before_save]
    on_after_update_callback(attr_names, options[:after_update]) if options[:after_update]
    on_before_update_callback(attr_names, options[:before_update]) if options[:before_update]

    Translatable.add_translatable self

  end
end

#translatable?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/translatable/active_record/macro.rb', line 44

def translatable?
  included_modules.include?(InstanceMethods)
end