class Hello::LocalesGenerator

Public Instance Methods

copy_locales() click to toggle source
# File lib/generators/hello/locales/locales_generator.rb, line 8
def copy_locales
  case
  when selected_locales == []
    puts_usage
    puts
  when selected_locales == ['all']
    copy_them(available_locales)
  when missing_locales.any?
    puts_usage
    puts_matching
    puts_missing
    puts
  else
    copy_them(matching_locales)
  end
end

Protected Instance Methods

available_locales() click to toggle source
# File lib/generators/hello/locales/locales_generator.rb, line 61
def available_locales
  Dir[Hello.root.join('config', 'locales', '**', '*.yml')].map { |s| s.split('.')[-2] }
end
copy_them(locales) click to toggle source
# File lib/generators/hello/locales/locales_generator.rb, line 28
def copy_them(locales)
  locales.sort.each do |l|
    copy_file "config/locales/hello.#{l}.yml"
  end
end
matching_locales() click to toggle source
# File lib/generators/hello/locales/locales_generator.rb, line 53
def matching_locales
  selected_locales & available_locales
end
missing_locales() click to toggle source
# File lib/generators/hello/locales/locales_generator.rb, line 57
def missing_locales
  selected_locales - available_locales
end
puts_matching() click to toggle source
# File lib/generators/hello/locales/locales_generator.rb, line 47
def puts_matching
  puts
  puts "Matching:".light_green
  puts "  rails generate hello:locales #{matching_locales.sort.join(' ')}"
end
puts_missing() click to toggle source
# File lib/generators/hello/locales/locales_generator.rb, line 41
def puts_missing
  puts
  puts "Missing:".light_red
  puts "  rails generate hello:locales #{missing_locales.sort.join(' ')}"
end
puts_usage() click to toggle source
# File lib/generators/hello/locales/locales_generator.rb, line 34
def puts_usage
  puts
  puts "Usage:".light_yellow
  puts "  rails generate hello:locales all"
  puts "  rails generate hello:locales #{available_locales.sort.join(' ')}"
end