Module: ActiveRecord::Mlang

Included in:
Lang
Defined in:
lib/active_record/mlang.rb,
lib/active_record/mlang/lang.rb,
lib/active_record/mlang/text.rb,
lib/active_record/mlang/railtie.rb,
lib/active_record/mlang/lang_text.rb

Defined Under Namespace

Modules: ClassMethods, Text Classes: Lang, LangText, Railtie

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
# File 'lib/active_record/mlang.rb', line 7

def self.included(base)
  base.extend ClassMethods
  base.set_text_reflection
end

Instance Method Details

#text(locale_or_lang_id = nil) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/active_record/mlang.rb', line 54

def text(locale_or_lang_id=nil)
  return nil if !self.persisted?

  locale_or_lang_id ||= I18n.locale || I18n.default_locale
  return nil if !(lang = Lang[locale_or_lang_id])

  texts.find_or_create_by(lang_id: lang.id)
end