delfos 0.0.1.pre.beta → 0.0.1.pre.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ # These `Unstubbing` modules because we are testing something that redefines
5
+ # methods.
6
+
7
+ # We don't want to call the logging defined in
8
+ # `Delfos::Patching::MethodOverride#setup` multiple times. So we replace with
9
+ # the original definition, or to as close as possible.
10
+
11
+ # If there is a better way to do this please suggest
12
+
13
+ module Delfos
14
+ module Patching
15
+ module Unstubbing
16
+ module ClassMethods
17
+ def add_instance_to_unstub!(object)
18
+ instances_to_unstub.push(object)
19
+ end
20
+
21
+ def unstub_all!
22
+ instances_to_unstub.each(&:unstub!)
23
+ @instances_to_unstub = []
24
+ end
25
+
26
+ private
27
+
28
+ def instances_to_unstub
29
+ @instances_to_unstub ||= []
30
+ end
31
+ end
32
+
33
+ module InstanceMethods
34
+ def initialize(*args)
35
+ super(*args)
36
+ self.class.add_instance_to_unstub!(self) unless bail?
37
+ end
38
+
39
+ # This method is the inverse of `Delfos::Patching::MethodOverride#setup`
40
+ def unstub!
41
+ method = Delfos::MethodLogging::AddedMethods.find(klass, key)
42
+ return unless method
43
+ file = File.expand_path(__FILE__)
44
+
45
+ cm = class_method
46
+ if cm
47
+ method.unbind.bind(klass)
48
+ else
49
+ klass.send(:define_method, name) do |*args, **kw_args, &block|
50
+ arguments = Delfos::Patching::MethodOverride::MethodArguments.new(args, kw_args, block, cm)
51
+ arguments.apply_to(method.bind(self))
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
metadata CHANGED
@@ -1,116 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delfos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre.beta
4
+ version: 0.0.1.pre.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Burns
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-11 00:00:00.000000000 Z
11
+ date: 2016-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.7.2
17
20
  - - ">="
18
21
  - !ruby/object:Gem::Version
19
- version: '0'
22
+ version: 0.7.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ">="
27
+ - - "~>"
25
28
  - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: what_weve_got_here_is_an_error_to_communicate
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
29
+ version: 0.7.2
31
30
  - - ">="
32
31
  - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
32
+ version: 0.7.0
41
33
  - !ruby/object:Gem::Dependency
42
- name: bundler
34
+ name: pry-byebug
43
35
  requirement: !ruby/object:Gem::Requirement
44
36
  requirements:
45
37
  - - "~>"
46
38
  - !ruby/object:Gem::Version
47
- version: '1.11'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.11'
55
- - !ruby/object:Gem::Dependency
56
- name: byebug
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
39
+ version: '3.4'
59
40
  - - ">="
60
41
  - !ruby/object:Gem::Version
61
- version: '0'
42
+ version: 3.4.0
62
43
  type: :development
63
44
  prerelease: false
64
45
  version_requirements: !ruby/object:Gem::Requirement
65
46
  requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: awesome_print
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
47
+ - - "~>"
74
48
  - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
49
+ version: '3.4'
80
50
  - - ">="
81
51
  - !ruby/object:Gem::Version
82
- version: '0'
52
+ version: 3.4.0
83
53
  - !ruby/object:Gem::Dependency
84
54
  name: rake
85
55
  requirement: !ruby/object:Gem::Requirement
86
56
  requirements:
87
57
  - - "~>"
88
58
  - !ruby/object:Gem::Version
89
- version: 11.1.1
59
+ version: 11.3.0
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 11.3.0
90
63
  type: :development
91
64
  prerelease: false
92
65
  version_requirements: !ruby/object:Gem::Requirement
93
66
  requirements:
94
67
  - - "~>"
95
68
  - !ruby/object:Gem::Version
96
- version: 11.1.1
69
+ version: 11.3.0
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 11.3.0
97
73
  - !ruby/object:Gem::Dependency
98
74
  name: rspec
99
75
  requirement: !ruby/object:Gem::Requirement
100
76
  requirements:
101
77
  - - "~>"
102
78
  - !ruby/object:Gem::Version
103
- version: 3.4.0
79
+ version: 3.5.0
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.5.0
104
83
  type: :development
105
84
  prerelease: false
106
85
  version_requirements: !ruby/object:Gem::Requirement
107
86
  requirements:
108
87
  - - "~>"
109
88
  - !ruby/object:Gem::Version
110
- version: 3.4.0
111
- description: Just because
89
+ version: 3.5.0
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 3.5.0
93
+ description: Record every method call, call-site, arguments and their types in your
94
+ application code
112
95
  email:
113
- - markburns@notonthehighstreet.com
96
+ - markthedeveloper@gmail..com
114
97
  executables: []
115
98
  extensions: []
116
99
  extra_rdoc_files: []
@@ -121,18 +104,17 @@ files:
121
104
  - lib/delfos/distance/relation.rb
122
105
  - lib/delfos/execution_chain.rb
123
106
  - lib/delfos/method_logging.rb
107
+ - lib/delfos/method_logging/added_methods.rb
124
108
  - lib/delfos/method_logging/args.rb
125
109
  - lib/delfos/method_logging/code_location.rb
126
- - lib/delfos/method_logging/klass_determination.rb
127
110
  - lib/delfos/neo4j/distance_update.rb
128
111
  - lib/delfos/neo4j/execution_persistence.rb
129
112
  - lib/delfos/neo4j/informer.rb
130
113
  - lib/delfos/neo4j/query_execution.rb
131
- - lib/delfos/patching.rb
132
- - lib/delfos/patching_unstubbing_spec_helper.rb
133
- - lib/delfos/perform_patching.rb
134
- - lib/delfos/remove_patching.rb
135
- - lib/delfos/version.rb
114
+ - lib/delfos/patching/basic_object.rb
115
+ - lib/delfos/patching/basic_object_remove.rb
116
+ - lib/delfos/patching/method_override.rb
117
+ - lib/delfos/patching/unstubbing_spec_helper.rb
136
118
  homepage: https://github.com/markburns/delfos
137
119
  licenses:
138
120
  - MIT
@@ -157,5 +139,5 @@ rubyforge_project:
157
139
  rubygems_version: 2.5.1
158
140
  signing_key:
159
141
  specification_version: 4
160
- summary: Record every method call in an application
142
+ summary: Runtime type analysis
161
143
  test_files: []
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
- module Delfos
3
- module MethodLogging
4
- module KlassDetermination
5
- private
6
-
7
- def klass_for(object)
8
- if object.is_a?(Class)
9
- object
10
- else
11
- object.class
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,105 +0,0 @@
1
- # frozen_string_literal: true
2
- module Delfos
3
- class Patching
4
- class << self
5
- def perform(klass, name, private_methods, class_method:)
6
- new(klass, name, private_methods, class_method).setup
7
- end
8
-
9
- def added_methods
10
- @added_methods ||= {}
11
- end
12
-
13
- def method_definition_for(klass, key)
14
- # Find method definitions defined in klass or its ancestors
15
- super_klass = klass.ancestors.detect do |k|
16
- added_methods[k.to_s]
17
- end
18
-
19
- klass_hash = added_methods[super_klass.to_s] || {}
20
- klass_hash[key]
21
- end
22
- end
23
-
24
- attr_reader :klass, :name, :private_methods, :class_method
25
-
26
- def initialize(klass, name, private_methods, class_method)
27
- @klass = klass
28
- @name = name
29
- @private_methods = private_methods
30
- @class_method = class_method
31
- end
32
-
33
- # Redefine the method (only once) at runtime to enabling logging to Neo4j
34
- def setup
35
- return if ensure_method_recorded!
36
- original = original_method
37
- class_method = class_method()
38
- performer = method(:perform_call)
39
-
40
- method_defining_method.call(name) do |*args, **keyword_args, &block|
41
- MethodLogging.log(self, args, keyword_args, block, class_method, caller.dup, binding.dup, original)
42
-
43
- method_to_call = class_method ? original : original.bind(self)
44
- result = performer.call(method_to_call, args, keyword_args, block)
45
- Delfos::ExecutionChain.pop
46
- result
47
- end
48
- end
49
-
50
-
51
- private
52
-
53
- def perform_call(method_to_call, args, keyword_args, block)
54
- if keyword_args.empty?
55
- method_to_call.call(*args, &block)
56
- else
57
- method_to_call.call(*args, **keyword_args, &block)
58
- end
59
- end
60
-
61
- def original_method
62
- @original_method ||= class_method ? klass.singleton_method(name) : klass.instance_method(name)
63
- end
64
-
65
- def method_defining_method
66
- class_method ? klass.method(:define_singleton_method) : klass.method(:define_method)
67
- end
68
-
69
- def ensure_method_recorded!
70
- return true if bail?
71
-
72
- self.class.added_methods[klass.to_s] ||= {}
73
- self.class.added_methods[klass.to_s][key] = original_method.source_location
74
-
75
- false
76
- end
77
-
78
- def bail?
79
- method_has_been_added? || private_method? || exclude?
80
- end
81
-
82
- def method_has_been_added?
83
- return false unless self.class.added_methods[self]
84
- return false unless self.class.added_methods[self][klass]
85
-
86
- self.class.added_methods[klass][key]
87
- end
88
-
89
- def private_method?
90
- private_methods.include?(name.to_sym)
91
- end
92
-
93
- def exclude?
94
- ::Delfos::MethodLogging.exclude_from_logging?(original_method)
95
- end
96
-
97
- def key
98
- "#{type}_#{name}"
99
- end
100
-
101
- def type
102
- class_method ? "ClassMethod" : "InstanceMethod"
103
- end
104
- end
105
- end
@@ -1,44 +0,0 @@
1
- # This existence of these `Unstubbing` modules are an unfortunate side effect of trying to
2
- # test something that redefines methods. In order to not call the logging
3
- # defined in `Delfos::Patching#setup` multiple times we have to keep track of
4
- # and remove the method definitions and replace with the original definition
5
- # (or as close to the original as possible).
6
- #
7
- # If there is a better way to test Delfos::Patching without doing this then
8
- # please suggest or replace with a cleaner alternative
9
- module Unstubbing
10
- module ClassMethods
11
- def add_instance_to_unstub!(object)
12
- instances_to_unstub.push(object)
13
- end
14
-
15
- def unstub_all!
16
- instances_to_unstub.each(&:unstub!)
17
- end
18
-
19
- private
20
-
21
- def instances_to_unstub
22
- @instances_to_unstub ||= []
23
- end
24
- end
25
-
26
- module InstanceMethods
27
- def initialize(*args)
28
- super(*args)
29
- self.class.add_instance_to_unstub!(self) unless bail?
30
- end
31
-
32
- # This method is the inverse of `Delfos::Patching#setup`
33
- def unstub!
34
- original = original_method
35
- class_method = class_method()
36
- performer = method(:perform_call)
37
-
38
- method_defining_method.call(name) do |*args, **keyword_args, &block|
39
- method_to_call = class_method ? original : original.bind(self)
40
- performer.call(method_to_call, args, keyword_args, block)
41
- end
42
- end
43
- end
44
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
- require_relative "patching"
3
-
4
- class BasicObject
5
- def self.method_added(name)
6
- return if name == __method__
7
-
8
- ::Delfos::Patching.perform(self, name, private_instance_methods, class_method: false)
9
- end
10
-
11
- def self.singleton_method_added(name)
12
- return if name == __method__
13
-
14
- ::Delfos::Patching.perform(self, name, private_methods, class_method: true)
15
- end
16
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
- class BasicObject
3
- def self.method_added(*_args)
4
- nil
5
- end
6
-
7
- def self.singleton_method_added(*_args)
8
- nil
9
- end
10
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
- module Delfos
3
- VERSION = "0.0.1-beta"
4
- end