Class: Surrogate::SurrogateClassReflector

Inherits:
Struct
  • Object
show all
Defined in:
lib/surrogate/surrogate_class_reflector.rb

Overview

Reflects on the surrogate class to give info about methods that are useful for the comparer

It might make sense to not treat instance and class differently, but instead let whoever wants to use this instantiate it with both the class and the singleton class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#surrogate_classObject

Returns the value of attribute surrogate_class

Returns:

  • (Object)

    the current value of surrogate_class



8
9
10
# File 'lib/surrogate/surrogate_class_reflector.rb', line 8

def surrogate_class
  @surrogate_class
end

Instance Method Details

#class_api_methodsObject



41
42
43
# File 'lib/surrogate/surrogate_class_reflector.rb', line 41

def class_api_methods
  Set.new singleton_class_hatchery.api_method_names
end

#class_hatcheryObject



57
58
59
# File 'lib/surrogate/surrogate_class_reflector.rb', line 57

def class_hatchery
  @class_hatchery ||= surrogate_class.instance_variable_get :@hatchery
end

#class_inherited_methodsObject



45
46
47
# File 'lib/surrogate/surrogate_class_reflector.rb', line 45

def class_inherited_methods
  Set.new surrogate_class.singleton_class.instance_methods - surrogate_class.singleton_class.instance_methods(false)
end

#class_other_methodsObject



49
50
51
# File 'lib/surrogate/surrogate_class_reflector.rb', line 49

def class_other_methods
  Set.new(surrogate_class.singleton_class.instance_methods false) - class_api_methods - class_inherited_methods
end

#class_without_bodiesObject



53
54
55
# File 'lib/surrogate/surrogate_class_reflector.rb', line 53

def class_without_bodies
  Set.new singleton_class_hatchery.api_method_names.reject { |name| singleton_class_hatchery.api_method_for name }
end

#instance_api_methodsObject



25
26
27
# File 'lib/surrogate/surrogate_class_reflector.rb', line 25

def instance_api_methods
  Set.new class_hatchery.api_method_names
end

#instance_inherited_methodsObject



29
30
31
# File 'lib/surrogate/surrogate_class_reflector.rb', line 29

def instance_inherited_methods
  Set.new surrogate_class.instance_methods - surrogate_class.instance_methods(false)
end

#instance_other_methodsObject



33
34
35
# File 'lib/surrogate/surrogate_class_reflector.rb', line 33

def instance_other_methods
  Set.new(surrogate_class.instance_methods false) - instance_api_methods
end

#instance_without_bodiesObject



37
38
39
# File 'lib/surrogate/surrogate_class_reflector.rb', line 37

def instance_without_bodies
  Set.new class_hatchery.api_method_names.reject { |name| class_hatchery.api_method_for name }
end

#methodsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/surrogate/surrogate_class_reflector.rb', line 9

def methods
  { instance: {
      api:            instance_api_methods,
      inherited:      instance_inherited_methods,
      other:          instance_other_methods,
      without_bodies: instance_without_bodies,
    },
    class: {
      api:            class_api_methods,
      inherited:      class_inherited_methods,
      other:          class_other_methods,
      without_bodies: class_without_bodies,
    },
  }
end

#singleton_class_hatcheryObject



61
62
63
# File 'lib/surrogate/surrogate_class_reflector.rb', line 61

def singleton_class_hatchery
  @singleton_class_hatchery ||= surrogate_class.singleton_class.instance_variable_get :@hatchery
end