Module: I18n::Tasks::Ar::Model

Defined in:
lib/i18n/tasks/ar/model.rb

Class Method Summary collapse

Class Method Details

.final_hash(lang) ⇒ Object



30
31
32
33
34
# File 'lib/i18n/tasks/ar/model.rb', line 30

def final_hash lang
  result = {}
  result[lang.to_s] = { 'activerecord' => { 'models' => hash } }
  result
end

.hashObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/i18n/tasks/ar/model.rb', line 10

def hash
  if !names.empty?
    result = {}
    names.each do |name|
      result[slashed(name)] = { 'one' => real_name(name), 'other' => real_name(name).pluralize }
    end
    result
  else
    nil
  end
end

.namesObject



6
7
8
# File 'lib/i18n/tasks/ar/model.rb', line 6

def names
  ActiveRecord::Base.descendants.map(&:name)
end

.real_name(name) ⇒ Object



26
27
28
# File 'lib/i18n/tasks/ar/model.rb', line 26

def real_name name
  name.split('::').last
end

.slashed(name) ⇒ Object



22
23
24
# File 'lib/i18n/tasks/ar/model.rb', line 22

def slashed name
  name.underscore.gsub('::', '/')
end