C0 code coverage information
Generated on Tue Jun 09 17:50:05 +0900 2009 with
rcov 0.8.1.2
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.
1 #
-*- coding: utf-8 -*- 2
require 'nested_ajax' 3
4 module NestedAjax
5 module NameToDisplay
6 def self.included(base)
7
base.extend(ClassMethods)
8 base.instance_eval do 9
alias :belongs_to_without_nested_ajax :belongs_to 10 alias :belongs_to
:belongs_to_with_nested_ajax 11 12
alias :has_many_without_nested_ajax :has_many 13 alias :has_many
:has_many_with_nested_ajax 14 15
alias :has_one_without_nested_ajax :has_one 16 alias :has_one :has_one_with_nested_ajax 17 end 18 end 19 20 module ClassMethods 21 # If you want to use complex find or name for
nested_ajax, 22 # define
an instance method 23 #
def name_for_nested_ajax(context = {}) 24 # # return "name of record for nested_ajax"
25 # end 26 # 27 # and define an class method
28 # def
self.find_with_name(name, context = {}) 29 # # return [record1, record2] 30 # end 31 def name_for_nested_ajax(attr_name)
32
define_method(:name_for_nested_ajax){|*runtime_args| send(attr_name)}
33 # ここで
<<-"EOS"の代わりに、%{..}を使うとrcovが拾って
れません... 34
instance_eval(<<-"EOS") 35 def find_with_name(name, context = {}) 36 self.find(:all, :conditions =>
["#{attr_name} like ?", "%\#{name}%"], :order =>
:#{attr_name}) 37 end
38 EOS 39 end 40 41 def belongs_to_with_nested_ajax(*args, &block)
42 result =
belongs_to_without_nested_ajax(*args.dup, &block) 43
define_association_name_for_nested_ajax(*args) 44 result 45 end 46 47 def has_one_with_nested_ajax(*args, &block)
48 result =
has_one_without_nested_ajax(*args.dup, &block) 49
define_association_name_for_nested_ajax(*args) 50 result 51 end 52 53 def has_many_with_nested_ajax(*args, &block)
54 result =
has_many_without_nested_ajax(*args.dup, &block) 55
define_association_names_for_nested_ajax(*args) 56 result 57 end 58 59 def define_association_name_for_nested_ajax(*args)
60 args.extract_options!
61 args.each do
|association_name| 62
self.module_eval(%{ 63
def #{association_name}_name_for_nested_ajax 64
#{association_name}.name_for_nested_ajax("#{self.name}#{association_nam
}") if #{association_name} 65 end 66 }) 67 end 68 end 69 70
def define_association_names_for_nested_ajax(*args) 71 args.extract_options! 72 args.each do |association_name|
73 self.module_eval(%{
74 def
#{association_name.to_s.singularize}_names_for_nested_ajax 75 #{association_name}.map{|obj|
obj.name_for_nested_ajax("#{self.name}#{association_name}")} if
#{association_name} 76
end 77 }) 78 end 79 end 80 end 81 82 end 83 end
Generated using the rcov
code coverage analysis tool for Ruby version 0.8.1.2.