Class: AwesomeTranslations::Handlers::ModelHandler

Inherits:
BaseHandler
  • Object
show all
Defined in:
lib/awesome_translations/handlers/model_handler.rb

Instance Method Summary collapse

Methods inherited from BaseHandler

#add_translations_for_hash, #enabled?, #translations_for_hash_recursive

Instance Method Details

#groupsObject



2
3
4
5
6
7
8
9
10
11
# File 'lib/awesome_translations/handlers/model_handler.rb', line 2

def groups
  ArrayEnumerator.new do |yielder|
    AwesomeTranslations::ModelInspector.model_classes.each do |model_inspector|
      yielder << AwesomeTranslations::Group.new(
        id: model_inspector.clazz.name,
        handler: self
      )
    end
  end
end

#translations_for_group(group) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/awesome_translations/handlers/model_handler.rb', line 13

def translations_for_group(group)
  ArrayEnumerator.new do |yielder|
    model_inspector = AwesomeTranslations::ModelInspector.model_classes.find { |model_inspector_i| model_inspector_i.clazz.name == group.name }
    raise "No inspector by that name: #{group.name}" unless model_inspector

    model_names(model_inspector).each { |translation| yielder << translation }
    active_record_attributes(model_inspector).each { |translation| yielder << translation }
    paperclip_attachments(model_inspector).each { |translation| yielder << translation }
    relationships(model_inspector).each { |translation| yielder << translation }
    monetized_attributes(model_inspector).each { |translation| yielder << translation }
    globalize_attributes(model_inspector).each { |translation| yielder << translation }
  end
end