Module: Mongoid::Translate

Extended by:
ActiveSupport::Concern
Defined in:
lib/mongoid/translate.rb,
lib/mongoid_translate.rb,
lib/mongoid/translate/slug.rb,
lib/mongoid/translate/version.rb,
lib/mongoid/translate/resources.rb

Defined Under Namespace

Modules: ClassMethods, Resources, Slug

Constant Summary collapse

VERSION =
"1.0.2"

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/mongoid/translate.rb', line 40

def method_missing(method, *args, &block)
  if self.languages.include?(method)
    translations.where(language: method).one
  else
    super(method, *args, &block)
  end
end

Instance Method Details

#languagesArray

Return list of existing languages

Returns:

  • (Array)


28
29
30
# File 'lib/mongoid/translate.rb', line 28

def languages
  translations.map(&:language)
end

#main_translationDocument

Return main translation object

Returns:

  • (Document)


36
37
38
# File 'lib/mongoid/translate.rb', line 36

def main_translation
  translations.where(language: main_language).one
end