Class: Lolita::Translation::Record::ARRecord

Inherits:
AbstractRecord show all
Defined in:
lib/lolita-translation/record.rb

Instance Attribute Summary

Attributes inherited from AbstractRecord

#orm_record

Instance Method Summary collapse

Methods inherited from AbstractRecord

#initialize, #new_record?

Constructor Details

This class inherits a constructor from Lolita::Translation::Record::AbstractRecord

Instance Method Details

#association_keyObject



111
112
113
114
# File 'lib/lolita-translation/record.rb', line 111

def association_key
  association = adapter.reflect_on_association(association_name)
  association.key
end

#attribute(name) ⇒ Object



94
95
96
# File 'lib/lolita-translation/record.rb', line 94

def attribute(name)
  translation_string(orm_record.attributes[name.to_s],name)
end

#default_locale=(value) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/lolita-translation/record.rb', line 74

def default_locale=(value)
  if has_locale_column?
    orm_record.send(:"#{locale_field}=",value)
  else
    super
  end
end

#has_translation_for?(locale) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/lolita-translation/record.rb', line 116

def has_translation_for?(locale)
  !!find_translation_by_locale(locale)
end

#localeObject



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/lolita-translation/record.rb', line 82

def locale
  if has_locale_column?
    if value = orm_record.attributes[locale_field] and value.to_s.size > 0
      value
    else
      super
    end
  else
    system_default_locale
  end
end

#new_reocrd?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/lolita-translation/record.rb', line 107

def new_reocrd?
  orm_record.new_record?
end

#translated_attribute(name, options = {}) ⇒ Object



98
99
100
101
102
103
104
105
# File 'lib/lolita-translation/record.rb', line 98

def translated_attribute(name, options = {})
  translation_record = find_translation_by_locale(options[:locale])
  if translation_record and str = translation_string(translation_record.attributes[name.to_s],name) and str.size > 0
    str
  else
    attribute(name)
  end
end