C0 code coverage information
Generated on Sun Oct 26 11:17:55 -0500 2008 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 require 'aquarium/utils/type_utils'
2 require 'aquarium/utils/logic_error'
3
4 module Aquarium
5 module Utils
6 module MethodUtils
7
8 def self.method_args_to_hash *args
9 return {} if args.empty? || (args.size == 1 && args[0].nil?)
10 hash = (args[-1] and args[-1].kind_of? Hash) ? args.pop : {}
11 args.each do |arg|
12 if block_given?
13 hash[arg] = yield arg
14 else
15 hash[arg] = nil
16 end
17 end
18 hash
19 end
20
21 def self.visibility type_or_instance, method_sym, class_or_instance_only = nil, include_ancestors = true
22 find_method(type_or_instance, method_sym, class_or_instance_only, include_ancestors) do |t_or_o, msym, protection|
23 protection
24 end
25 end
26
27 def self.has_method type_or_instance, method_sym, class_or_instance_only = nil, include_ancestors = true
28 found = find_method(type_or_instance, method_sym, class_or_instance_only, include_ancestors) do |t_or_o, msym, protection|
29 true
30 end
31 found ? true : false # found could be nil; return false, if so
32 end
33
34 def self.find_method type_or_instance, method_sym, class_or_instance_only = nil, include_ancestors = true
35 meta_method_suffixes = determine_meta_method_suffixes type_or_instance, class_or_instance_only
36 meta_method_suffixes.each do |suffix|
37 %w[public protected private].each do |protection|
38 meta_method = "#{protection}_#{suffix}"
39 found_methods = type_or_instance.send(meta_method, include_ancestors)
40 if found_methods.include?(method_sym.to_s)
41 return yield(type_or_instance, method_sym, protection.intern)
42 end
43 end
44 end
45 nil
46 end
47
48 # Which type in a hierarchy actually defines a method?
49 def self.definer type_or_instance, method_sym, class_or_instance_only = nil
50 return nil if type_or_instance.nil? or method_sym.nil?
51 return nil unless has_method(type_or_instance, method_sym, class_or_instance_only)
52 ancestors = ancestors_for type_or_instance
53 determine_definer ancestors, type_or_instance, method_sym, class_or_instance_only
54 end
55
56 private
57
58 # For objects, include the singleton/eigenclass in case a method of interest was actually defined just for the object.
59 def self.ancestors_for object
60 if Aquarium::Utils::TypeUtils.is_type? object
61 object.ancestors
62 else
63 eigen = (class << object; self; end)
64 [eigen] + eigen.ancestors
65 end
66 end
67
68 def self.determine_definer ancestors, type_or_instance, method_sym, class_or_instance_only
69 candidates = ancestors.find_all {|a| has_method(a, method_sym, class_or_instance_only, false) { true }}
70 if candidates.size == 2 and Aquarium::Utils::TypeUtils.is_type?(type_or_instance) == false
71 return determine_actual_parent(type_or_instance, candidates)
72 end
73 candidates.size == 1 ? candidates.first : raise(Aquarium::Utils::LogicError.new("Bug: Got multiple types #{candidates.inspect} that implement method #{method_sym}"))
74 end
75
76 def self.determine_actual_parent object, candidates
77 return nil unless (object.is_a?(candidates[0]) and object.is_a?(candidates[1]))
78 candidates[0].name == "" ? candidates[1] : candidates[0]
79 end
80
81 def self.determine_meta_method_suffixes type_or_instance, class_or_instance_only
82 limits = class_or_instance_only.nil? ? [:instance_method_only, :class_method_only] : [class_or_instance_only]
83 meta_method_suffixes = []
84 limits.each do |limit|
85 if Aquarium::Utils::TypeUtils.is_type? type_or_instance
86 meta_method_suffixes << "instance_methods" if limit == :instance_method_only
87 meta_method_suffixes << "methods" if limit == :class_method_only
88 else
89 meta_method_suffixes << "methods" if limit == :instance_method_only
90 end
91 end
92 meta_method_suffixes
93 end
94 end
95 end
96 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.