Class: Surrogate::ApiComparer
- Inherits:
-
Object
- Object
- Surrogate::ApiComparer
- Defined in:
- lib/surrogate/api_comparer.rb
Overview
compares a surrogate to an object
Instance Attribute Summary collapse
-
#actual ⇒ Object
Returns the value of attribute actual.
-
#surrogate ⇒ Object
Returns the value of attribute surrogate.
Instance Method Summary collapse
- #actual_methods ⇒ Object
-
#class_names ⇒ Object
names are only shown for methods on both objects.
- #class_not_on_actual ⇒ Object
- #class_not_on_surrogate ⇒ Object
-
#class_types ⇒ Object
types are only shown for methods on both objects.
- #compare ⇒ Object
-
#initialize(actual, surrogate) ⇒ ApiComparer
constructor
A new instance of ApiComparer.
-
#instance_names ⇒ Object
names are only shown for methods on both objects.
- #instance_not_on_actual ⇒ Object
- #instance_not_on_surrogate ⇒ Object
-
#instance_types ⇒ Object
types are only shown for methods on both objects.
- #surrogate_methods ⇒ Object
Constructor Details
#initialize(actual, surrogate) ⇒ ApiComparer
Returns a new instance of ApiComparer.
11 12 13 14 15 16 |
# File 'lib/surrogate/api_comparer.rb', line 11 def initialize(actual, surrogate) unless surrogate.instance_variable_get(:@hatchery).kind_of?(Hatchery) && surrogate.instance_variable_get(:@hatchling).kind_of?(Hatchling) surrogate, actual = actual, surrogate end self.surrogate, self.actual = surrogate, actual end |
Instance Attribute Details
#actual ⇒ Object
Returns the value of attribute actual.
9 10 11 |
# File 'lib/surrogate/api_comparer.rb', line 9 def actual @actual end |
#surrogate ⇒ Object
Returns the value of attribute surrogate.
9 10 11 |
# File 'lib/surrogate/api_comparer.rb', line 9 def surrogate @surrogate end |
Instance Method Details
#actual_methods ⇒ Object
22 23 24 |
# File 'lib/surrogate/api_comparer.rb', line 22 def actual_methods @actual_methods ||= PorcReflector.new(actual).methods end |
#class_names ⇒ Object
names are only shown for methods on both objects
94 95 96 97 98 99 100 |
# File 'lib/surrogate/api_comparer.rb', line 94 def class_names class_methods_that_should_match.each_with_object Hash.new do |method_name, hash| surrogate_name, actual_name = class_parameter_names_for method_name next if surrogate_name == actual_name || method_name == :clone # ugh :( hash[method_name] = { surrogate: surrogate_name, actual: actual_name } end end |
#class_not_on_actual ⇒ Object
57 58 59 |
# File 'lib/surrogate/api_comparer.rb', line 57 def class_not_on_actual surrogate_methods[:class][:api] - actual_methods[:class][:inherited] - actual_methods[:class][:other] end |
#class_not_on_surrogate ⇒ Object
52 53 54 55 |
# File 'lib/surrogate/api_comparer.rb', line 52 def class_not_on_surrogate (actual_methods[:class][:inherited] + actual_methods[:class][:other]) - (surrogate_methods[:class][:inherited] + surrogate_methods[:class][:api]) end |
#class_types ⇒ Object
types are only shown for methods on both objects
76 77 78 79 80 81 82 |
# File 'lib/surrogate/api_comparer.rb', line 76 def class_types class_methods_that_should_match.each_with_object Hash.new do |name, hash| surrogate_type, actual_type = class_types_for name next if surrogate_type == actual_type || name == :clone # ugh :( hash[name] = { surrogate: surrogate_type, actual: actual_type } end end |
#compare ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/surrogate/api_comparer.rb', line 26 def compare @compare ||= { instance: { not_on_surrogate: instance_not_on_surrogate, not_on_actual: instance_not_on_actual, types: instance_types, names: instance_names, }, class: { not_on_surrogate: class_not_on_surrogate, not_on_actual: class_not_on_actual, types: class_types, names: class_names, }, } end |
#instance_names ⇒ Object
names are only shown for methods on both objects
103 104 105 106 107 108 109 |
# File 'lib/surrogate/api_comparer.rb', line 103 def instance_names instance_methods_that_should_match.each_with_object Hash.new do |method_name, hash| surrogate_name, actual_name = instance_parameter_names_for method_name next if surrogate_name == actual_name hash[method_name] = { surrogate: surrogate_name, actual: actual_name } end end |
#instance_not_on_actual ⇒ Object
48 49 50 |
# File 'lib/surrogate/api_comparer.rb', line 48 def instance_not_on_actual surrogate_methods[:instance][:api] - actual_methods[:instance][:inherited] - actual_methods[:instance][:other] end |
#instance_not_on_surrogate ⇒ Object
43 44 45 46 |
# File 'lib/surrogate/api_comparer.rb', line 43 def instance_not_on_surrogate (actual_methods[:instance][:inherited] + actual_methods[:instance][:other]) - (surrogate_methods[:instance][:inherited] + surrogate_methods[:instance][:api]) end |
#instance_types ⇒ Object
types are only shown for methods on both objects
85 86 87 88 89 90 91 |
# File 'lib/surrogate/api_comparer.rb', line 85 def instance_types instance_methods_that_should_match.each_with_object Hash.new do |name, hash| surrogate_type, actual_type = instance_types_for name next if surrogate_type == actual_type hash[name] = { surrogate: surrogate_type, actual: actual_type } end end |
#surrogate_methods ⇒ Object
18 19 20 |
# File 'lib/surrogate/api_comparer.rb', line 18 def surrogate_methods @surrogate_methods ||= SurrogateClassReflector.new(surrogate).methods end |