C0 code coverage information

Generated on Fri Aug 25 11:26:30 PDT 2006 with rcov 0.7.0


Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
Name Total lines Lines of code Total coverage Code coverage
lib/localization.rb 88 65
100.0% 
100.0% 
 1 require 'iconv'
 2 
 3 module Localization
 4   
 5   LOCALIZED_STRINGS = {}
 6 
 7   def l(symbol, *arguments)
 8     language = CONFIG[:default_language]
 9 
10     symbol = symbol.to_sym if symbol.is_a? String
11 
12     # translation of an LString is simply a call to to_s
13     return symbol.to_s if symbol.is_a? LString
14   
15     # translation of an array
16     if symbol.is_a? Array 
17       raise ArgumentError.new("Cannot translate an empty array") if symbol.empty?
18       raise ArgumentError.new("Symbol is an array, arguments must be empty") unless arguments.empty?
19       arguments = symbol
20       symbol = arguments.shift
21     end
22 
23     begin
24       translation = (LOCALIZED_STRINGS[language][symbol] or
25                        LOCALIZED_STRINGS['en'][symbol] or
26                        symbol.to_s)
27     rescue
28       translation = symbol.to_s
29     end
30 
31     begin
32       return translation % arguments
33     rescue => e
34       raise ArgumentError.new("Translation value #{translation.inspect} " + 
35           "with arguments #{arguments.inspect} caused error '#{e.message}'")
36     end
37   end
38 
39   def valid_language?(language)
40     LOCALIZED_STRINGS.has_key? language
41   end
42 
43   def self.load_localized_strings
44     # Load language files
45     Dir[RAILS_ROOT + '/lang/*.yaml'].each do |filename|
46       filename =~ /(([a-z]+_?)+)\.yaml$/
47       hash = YAML::load(File.read(filename))
48       file_charset = hash['file_charset'] || 'ascii'
49       lang = $1
50 
51       # convert string keys to symbols
52       symbol_hash = Hash.new
53       Iconv.open(CONFIG[:web_charset], file_charset) do |i|
54         hash.each do |key, value|
55           symbol_hash[key.to_sym] = i.iconv(value)
56           if key =~ /^active_record_errors_(.*)/
57             ActiveRecord::Errors.default_error_messages[$1.to_sym] =
58               symbol_hash[key.to_sym]
59           end
60         end
61       end
62 
63       LOCALIZED_STRINGS[lang] = symbol_hash
64     end
65   end
66 
67   class LString
68   
69     include Localization
70     
71     def initialize(symbol, arguments)
72       @symbol, @arguments = symbol, arguments
73     end
74 
75     def to_s
76       l(@symbol, @arguments)
77     end
78   end
79 
80   # redefinition of ActionMail::Base#render_message, that adds locale suffix to
81   # the template name
82   ActionMailer::Base.module_eval <<-EOL
83   private
84   def render_message(method_name, body)
85     initialize_template_class(body).render_file(method_name + "_#{CONFIG[:default_language]}")
86   end
87   EOL
88 end

Generated using the rcov code coverage analysis tool for Ruby version 0.7.0.

Valid XHTML 1.0! Valid CSS!