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 17 |
# 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) Kernel.warn "You said #{actual} should substitute for #{surrogate}`, but as of 0.6.2, this should be asserted in the other direction." 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
23 24 25 |
# File 'lib/surrogate/api_comparer.rb', line 23 def actual_methods @actual_methods ||= PorcReflector.new(actual).methods end |
#class_names ⇒ Object
names are only shown for methods on both objects
85 86 87 88 89 90 91 |
# File 'lib/surrogate/api_comparer.rb', line 85 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 hash[method_name] = { surrogate: surrogate_name, actual: actual_name } end end |
#class_not_on_actual ⇒ Object
58 59 60 |
# File 'lib/surrogate/api_comparer.rb', line 58 def class_not_on_actual surrogate_methods[:class][:api] - actual_methods[:class][:inherited] - actual_methods[:class][:other] end |
#class_not_on_surrogate ⇒ Object
53 54 55 56 |
# File 'lib/surrogate/api_comparer.rb', line 53 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
67 68 69 70 71 72 73 |
# File 'lib/surrogate/api_comparer.rb', line 67 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 hash[name] = { surrogate: surrogate_type, actual: actual_type } end end |
#compare ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/surrogate/api_comparer.rb', line 27 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
94 95 96 97 98 99 100 |
# File 'lib/surrogate/api_comparer.rb', line 94 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
49 50 51 |
# File 'lib/surrogate/api_comparer.rb', line 49 def instance_not_on_actual surrogate_methods[:instance][:api] - actual_methods[:instance][:inherited] - actual_methods[:instance][:other] end |
#instance_not_on_surrogate ⇒ Object
44 45 46 47 |
# File 'lib/surrogate/api_comparer.rb', line 44 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
76 77 78 79 80 81 82 |
# File 'lib/surrogate/api_comparer.rb', line 76 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
19 20 21 |
# File 'lib/surrogate/api_comparer.rb', line 19 def surrogate_methods @surrogate_methods ||= SurrogateClassReflector.new(surrogate).methods end |