delfos 0.0.1 → 0.0.2.pre.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/delfos.rb +72 -13
- data/lib/delfos/call_stack.rb +9 -9
- data/lib/delfos/call_stack/stack.rb +18 -18
- data/lib/delfos/file_system.rb +16 -0
- data/lib/delfos/file_system/app_directories.rb +42 -0
- data/lib/delfos/file_system/common_path.rb +17 -11
- data/lib/delfos/file_system/distance_calculation.rb +12 -3
- data/lib/delfos/file_system/path_determination.rb +4 -1
- data/lib/delfos/file_system/relation.rb +1 -0
- data/lib/delfos/method_trace.rb +59 -0
- data/lib/delfos/method_trace/call_handler.rb +48 -0
- data/lib/delfos/method_trace/code_location.rb +35 -0
- data/lib/delfos/method_trace/code_location/call_site.rb +38 -0
- data/lib/delfos/method_trace/code_location/container_method_factory.rb +71 -0
- data/lib/delfos/method_trace/code_location/eval_in_caller.rb +17 -0
- data/lib/delfos/method_trace/code_location/filename_helpers.rb +46 -0
- data/lib/delfos/method_trace/code_location/method.rb +58 -0
- data/lib/delfos/neo4j.rb +4 -4
- data/lib/delfos/neo4j/batch/execution.rb +30 -88
- data/lib/delfos/neo4j/batch/retryable.rb +101 -0
- data/lib/delfos/neo4j/call_site_query.rb +89 -0
- data/lib/delfos/neo4j/distance/call_site_fetcher.rb +1 -0
- data/lib/delfos/neo4j/distance/update.rb +22 -5
- data/lib/delfos/neo4j/live/call_site_logger.rb +17 -0
- data/lib/delfos/neo4j/offline/call_site_logger.rb +39 -0
- data/lib/delfos/neo4j/offline/importer.rb +68 -0
- data/lib/delfos/neo4j/query_execution/errors.rb +13 -3
- data/lib/delfos/neo4j/query_execution/http.rb +1 -0
- data/lib/delfos/neo4j/query_execution/http_query.rb +20 -15
- data/lib/delfos/neo4j/query_execution/sync.rb +1 -0
- data/lib/delfos/neo4j/query_execution/transactional.rb +24 -13
- data/lib/delfos/neo4j/schema.rb +5 -19
- data/lib/delfos/setup.rb +76 -44
- metadata +77 -18
- data/lib/delfos/method_logging.rb +0 -52
- data/lib/delfos/method_logging/call_site_parsing.rb +0 -74
- data/lib/delfos/method_logging/code_location.rb +0 -89
- data/lib/delfos/method_logging/method_parameters.rb +0 -53
- data/lib/delfos/neo4j/call_stack_query.rb +0 -88
- data/lib/delfos/neo4j/informer.rb +0 -128
- data/lib/delfos/patching/basic_object.rb +0 -14
- data/lib/delfos/patching/basic_object_remove.rb +0 -7
- data/lib/delfos/patching/method_cache.rb +0 -83
- data/lib/delfos/patching/method_override.rb +0 -148
- data/lib/delfos/patching/module_defining_methods.rb +0 -105
- data/lib/delfos/patching/unstubber.rb +0 -34
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "json"
|
3
4
|
require "uri"
|
4
5
|
require "time"
|
@@ -12,10 +13,10 @@ module Delfos
|
|
12
13
|
class Transactional
|
13
14
|
include HttpQuery
|
14
15
|
|
15
|
-
def self.
|
16
|
-
response = Http.new(
|
16
|
+
def self.commit!(url)
|
17
|
+
response = Http.new(url).post({ statements: [] }.to_json)
|
17
18
|
|
18
|
-
check_for_error(
|
19
|
+
check_for_error(url, response)
|
19
20
|
|
20
21
|
response.code == "200"
|
21
22
|
end
|
@@ -25,27 +26,37 @@ module Delfos
|
|
25
26
|
def self.check_for_error(uri, response)
|
26
27
|
return if response.code[VALID_RESPONSE_MATCHER]
|
27
28
|
|
28
|
-
if response.code == "404"
|
29
|
-
raise ExpiredTransaction.new(uri, response)
|
30
|
-
end
|
29
|
+
raise ExpiredTransaction.new(uri, response) if response.code == "404"
|
31
30
|
|
32
31
|
raise InvalidCommit.new(uri, response)
|
33
32
|
end
|
34
33
|
|
35
34
|
def perform
|
36
|
-
|
37
|
-
|
38
|
-
raise InvalidQuery.new(json["errors"], query, params) if errors?
|
39
|
-
|
40
|
-
transaction_url = URI.parse header("location") if header("location")
|
41
|
-
commit_url = URI.parse json["commit"] if json["commit"]
|
42
|
-
expires = Time.parse json["transaction"]["expires"] if json["transaction"]
|
35
|
+
validate!
|
43
36
|
|
44
37
|
[transaction_url, commit_url, expires]
|
45
38
|
end
|
46
39
|
|
47
40
|
private
|
48
41
|
|
42
|
+
def transaction_url
|
43
|
+
URI.parse(header("location")) if header("location")
|
44
|
+
end
|
45
|
+
|
46
|
+
def commit_url
|
47
|
+
URI.parse(json["commit"]) if json["commit"]
|
48
|
+
end
|
49
|
+
|
50
|
+
def expires
|
51
|
+
Time.parse json["transaction"]["expires"] if json["transaction"]
|
52
|
+
end
|
53
|
+
|
54
|
+
def validate!
|
55
|
+
self.class.check_for_error(uri, response)
|
56
|
+
|
57
|
+
raise InvalidQuery.new(json["errors"], query, params) if errors?
|
58
|
+
end
|
59
|
+
|
49
60
|
def header(name)
|
50
61
|
response.each_header.to_a.find { |n, _| n == name }&.last
|
51
62
|
end
|
data/lib/delfos/neo4j/schema.rb
CHANGED
@@ -1,38 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Delfos
|
3
4
|
module Neo4j
|
4
5
|
module Schema
|
5
6
|
extend self
|
6
7
|
|
7
8
|
def ensure_constraints!(required)
|
8
|
-
log "-" * 80
|
9
9
|
log "checking constraints"
|
10
|
-
log Time.now
|
11
|
-
log "-" * 80
|
12
10
|
|
13
11
|
if satisfies_constraints?(required)
|
14
12
|
log "Neo4j schema constraints satisfied"
|
15
13
|
else
|
16
|
-
|
17
|
-
error "Neo4j schema constraints not satisfied - adding"
|
18
|
-
error Time.now
|
14
|
+
log "Neo4j schema constraints not satisfied - adding", :warn
|
19
15
|
|
20
16
|
required.each do |label, attribute|
|
21
17
|
create_constraint(label, attribute)
|
22
18
|
end
|
23
19
|
|
24
|
-
log "-" * 80
|
25
20
|
log "Constraints added"
|
26
|
-
log Time.now
|
27
21
|
end
|
28
22
|
end
|
29
23
|
|
30
24
|
private
|
31
25
|
|
32
|
-
def error(s)
|
33
|
-
log(s, :error)
|
34
|
-
end
|
35
|
-
|
36
26
|
def log(s, type = :debug)
|
37
27
|
Delfos.logger.send(type, s)
|
38
28
|
end
|
@@ -56,14 +46,10 @@ module Delfos
|
|
56
46
|
def fetch_existing_constraints
|
57
47
|
response = QueryExecution::Http.new(constraints_uri).get
|
58
48
|
|
59
|
-
|
60
|
-
JSON.parse response.body
|
61
|
-
else
|
62
|
-
raise IOError.new uri, response
|
63
|
-
end
|
64
|
-
end
|
49
|
+
raise IOError.new uri, response unless response.code == "200"
|
65
50
|
|
66
|
-
|
51
|
+
JSON.parse response.body
|
52
|
+
end
|
67
53
|
|
68
54
|
def constraints_uri
|
69
55
|
Delfos.neo4j.uri_for("/db/data/schema/constraint")
|
data/lib/delfos/setup.rb
CHANGED
@@ -1,88 +1,120 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Delfos
|
3
4
|
module Setup
|
4
5
|
extend self
|
5
6
|
attr_accessor :neo4j
|
6
7
|
|
7
|
-
def perform!(call_site_logger: nil,
|
8
|
-
|
9
|
-
|
8
|
+
def perform!(call_site_logger: nil,
|
9
|
+
application_directories: nil,
|
10
|
+
offline_query_saving: nil)
|
11
|
+
self.application_directories = application_directories if application_directories
|
12
|
+
self.call_site_logger = call_site_logger if call_site_logger
|
13
|
+
|
14
|
+
assign_offline_attributes(offline_query_saving)
|
10
15
|
|
11
|
-
|
16
|
+
require "delfos/method_trace"
|
17
|
+
::Delfos::MethodTrace.trace!
|
12
18
|
end
|
13
19
|
|
14
20
|
def application_directories=(dirs)
|
15
|
-
dirs ||= %w
|
21
|
+
dirs ||= %w[app lib]
|
16
22
|
require "pathname"
|
17
|
-
Delfos.application_directories = Array(dirs).map { |f| Pathname.new(
|
18
|
-
end
|
19
|
-
|
20
|
-
def call_site_logger
|
21
|
-
@call_site_logger ||= default_call_site_logger
|
23
|
+
Delfos.application_directories = Array(dirs).map { |f| Pathname.new(f.to_s).expand_path }
|
22
24
|
end
|
23
25
|
|
24
26
|
def call_site_logger=(call_site_logger)
|
25
|
-
|
27
|
+
Delfos.call_site_logger = call_site_logger || default_call_site_logger
|
26
28
|
end
|
27
29
|
|
28
30
|
def default_call_site_logger
|
29
|
-
Delfos.
|
31
|
+
if Delfos.offline_query_saving
|
32
|
+
require "delfos/neo4j/offline/call_site_logger"
|
33
|
+
Delfos:: Neo4j::Offline::CallSiteLogger.new
|
34
|
+
else
|
35
|
+
Delfos.setup_neo4j!
|
36
|
+
|
37
|
+
require "delfos/neo4j/live/call_site_logger"
|
38
|
+
Delfos:: Neo4j::Live::CallSiteLogger.new
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def disable!
|
43
|
+
disable_tracepoint!
|
44
|
+
|
45
|
+
reset_call_stack!
|
46
|
+
reset_batch!
|
47
|
+
|
48
|
+
reset_top_level_variables!
|
49
|
+
reset_app_directories!
|
50
|
+
end
|
30
51
|
|
31
|
-
|
32
|
-
|
52
|
+
def disable_tracepoint!
|
53
|
+
require "delfos/method_trace"
|
54
|
+
::Delfos::MethodTrace.disable!
|
33
55
|
end
|
34
56
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
57
|
+
def reset_call_stack!
|
58
|
+
ignoring_undefined("Delfos::CallStack") do |k|
|
59
|
+
k.pop_until_top!
|
60
|
+
k.reset!
|
39
61
|
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def reset_batch!
|
65
|
+
Delfos.batch_size = nil
|
40
66
|
|
41
|
-
|
67
|
+
ignoring_undefined "Delfos::Neo4j::Batch::Retryable" do |b|
|
42
68
|
begin
|
43
|
-
|
44
|
-
|
45
|
-
|
69
|
+
with_rescue { b.flush! }
|
70
|
+
ensure
|
71
|
+
b.instance = nil
|
46
72
|
end
|
47
|
-
|
48
|
-
Delfos::Neo4j::Batch::Execution.reset!
|
49
73
|
end
|
74
|
+
end
|
50
75
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
remove_cached_methods!
|
55
|
-
|
56
|
-
remove_patching!
|
57
|
-
|
58
|
-
Delfos::MethodLogging.reset! if defined?(Delfos::MethodLogging) && Delfos::MethodLogging.respond_to?(:reset!)
|
76
|
+
def reset_app_directories!
|
77
|
+
ignoring_undefined("Delfos::FileSystem::AppDirectories", &:reset!)
|
78
|
+
end
|
59
79
|
|
80
|
+
def reset_top_level_variables!
|
81
|
+
Delfos.offline_query_saving = nil
|
82
|
+
Delfos.offline_query_filename = nil
|
60
83
|
Delfos.neo4j = nil
|
61
84
|
Delfos.logger = nil
|
62
85
|
Delfos.application_directories = nil
|
63
86
|
Delfos.call_site_logger = nil
|
64
|
-
|
87
|
+
Delfos.max_query_size = nil
|
65
88
|
Delfos.neo4j = nil
|
66
89
|
end
|
67
90
|
|
68
|
-
|
69
|
-
|
91
|
+
# This method allows resetting in between every spec. So we avoid load
|
92
|
+
# order issues in cases where we have not run particular specs that require
|
93
|
+
# and define these constants
|
94
|
+
def ignoring_undefined(k)
|
95
|
+
o = Object.const_get(k)
|
96
|
+
yield(o)
|
97
|
+
rescue NameError => e
|
98
|
+
raise unless e.message[k]
|
99
|
+
end
|
70
100
|
|
71
|
-
|
101
|
+
def with_rescue
|
102
|
+
yield
|
103
|
+
rescue Delfos::Neo4j::QueryExecution::ExpiredTransaction
|
104
|
+
puts # no-op
|
72
105
|
end
|
73
106
|
|
74
|
-
def
|
75
|
-
return unless
|
107
|
+
def assign_offline_attributes(offline_query_saving)
|
108
|
+
return unless offline_query_saving
|
109
|
+
Delfos.offline_query_saving = offline_query_saving
|
76
110
|
|
77
|
-
Delfos
|
111
|
+
Delfos.offline_query_filename = filename_from(offline_query_saving)
|
78
112
|
end
|
79
113
|
|
80
|
-
def
|
81
|
-
|
82
|
-
end
|
114
|
+
def filename_from(offline_query_saving)
|
115
|
+
return offline_query_saving if offline_query_saving.is_a?(String)
|
83
116
|
|
84
|
-
|
85
|
-
load "delfos/patching/basic_object.rb"
|
117
|
+
"delfos_query_parameters.json"
|
86
118
|
end
|
87
119
|
end
|
88
120
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delfos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2.pre.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Burns
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: binding_of_caller
|
@@ -30,8 +30,64 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 0.7.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: simplecov
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec_junit_formatter
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.2.3
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.2.3
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: codeclimate-test-reporter
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
33
75
|
- !ruby/object:Gem::Dependency
|
34
76
|
name: webmock
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 2.3.2
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 2.3.2
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rake-compiler
|
35
91
|
requirement: !ruby/object:Gem::Requirement
|
36
92
|
requirements:
|
37
93
|
- - ">="
|
@@ -115,32 +171,35 @@ files:
|
|
115
171
|
- lib/delfos.rb
|
116
172
|
- lib/delfos/call_stack.rb
|
117
173
|
- lib/delfos/call_stack/stack.rb
|
174
|
+
- lib/delfos/file_system.rb
|
175
|
+
- lib/delfos/file_system/app_directories.rb
|
118
176
|
- lib/delfos/file_system/common_path.rb
|
119
177
|
- lib/delfos/file_system/distance_calculation.rb
|
120
178
|
- lib/delfos/file_system/path_determination.rb
|
121
179
|
- lib/delfos/file_system/relation.rb
|
122
|
-
- lib/delfos/
|
123
|
-
- lib/delfos/
|
124
|
-
- lib/delfos/
|
125
|
-
- lib/delfos/
|
180
|
+
- lib/delfos/method_trace.rb
|
181
|
+
- lib/delfos/method_trace/call_handler.rb
|
182
|
+
- lib/delfos/method_trace/code_location.rb
|
183
|
+
- lib/delfos/method_trace/code_location/call_site.rb
|
184
|
+
- lib/delfos/method_trace/code_location/container_method_factory.rb
|
185
|
+
- lib/delfos/method_trace/code_location/eval_in_caller.rb
|
186
|
+
- lib/delfos/method_trace/code_location/filename_helpers.rb
|
187
|
+
- lib/delfos/method_trace/code_location/method.rb
|
126
188
|
- lib/delfos/neo4j.rb
|
127
189
|
- lib/delfos/neo4j/batch/execution.rb
|
128
|
-
- lib/delfos/neo4j/
|
190
|
+
- lib/delfos/neo4j/batch/retryable.rb
|
191
|
+
- lib/delfos/neo4j/call_site_query.rb
|
129
192
|
- lib/delfos/neo4j/distance/call_site_fetcher.rb
|
130
193
|
- lib/delfos/neo4j/distance/update.rb
|
131
|
-
- lib/delfos/neo4j/
|
194
|
+
- lib/delfos/neo4j/live/call_site_logger.rb
|
195
|
+
- lib/delfos/neo4j/offline/call_site_logger.rb
|
196
|
+
- lib/delfos/neo4j/offline/importer.rb
|
132
197
|
- lib/delfos/neo4j/query_execution/errors.rb
|
133
198
|
- lib/delfos/neo4j/query_execution/http.rb
|
134
199
|
- lib/delfos/neo4j/query_execution/http_query.rb
|
135
200
|
- lib/delfos/neo4j/query_execution/sync.rb
|
136
201
|
- lib/delfos/neo4j/query_execution/transactional.rb
|
137
202
|
- lib/delfos/neo4j/schema.rb
|
138
|
-
- lib/delfos/patching/basic_object.rb
|
139
|
-
- lib/delfos/patching/basic_object_remove.rb
|
140
|
-
- lib/delfos/patching/method_cache.rb
|
141
|
-
- lib/delfos/patching/method_override.rb
|
142
|
-
- lib/delfos/patching/module_defining_methods.rb
|
143
|
-
- lib/delfos/patching/unstubber.rb
|
144
203
|
- lib/delfos/setup.rb
|
145
204
|
homepage: https://github.com/markburns/delfos
|
146
205
|
licenses:
|
@@ -155,15 +214,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
214
|
requirements:
|
156
215
|
- - ">="
|
157
216
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
217
|
+
version: 2.3.0
|
159
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
219
|
requirements:
|
161
|
-
- - "
|
220
|
+
- - ">"
|
162
221
|
- !ruby/object:Gem::Version
|
163
|
-
version:
|
222
|
+
version: 1.3.1
|
164
223
|
requirements: []
|
165
224
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.
|
225
|
+
rubygems_version: 2.6.8
|
167
226
|
signing_key:
|
168
227
|
specification_version: 4
|
169
228
|
summary: Runtime type analysis
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "delfos/file_system/common_path"
|
3
|
-
|
4
|
-
require_relative "method_logging/code_location"
|
5
|
-
require_relative "method_logging/method_parameters"
|
6
|
-
|
7
|
-
module Delfos
|
8
|
-
module MethodLogging
|
9
|
-
extend self
|
10
|
-
|
11
|
-
def save_call_stack(call_sites, execution_number)
|
12
|
-
Delfos.call_site_logger.save_call_stack(call_sites, execution_number)
|
13
|
-
end
|
14
|
-
|
15
|
-
def log(call_site, called_object, called_method, class_method, parameters)
|
16
|
-
called_code = CodeLocation.from_called(called_object, called_method, class_method)
|
17
|
-
|
18
|
-
Delfos.call_site_logger.log(parameters, call_site, called_code)
|
19
|
-
end
|
20
|
-
|
21
|
-
def exclude?(method)
|
22
|
-
file, = method.source_location
|
23
|
-
return true unless file
|
24
|
-
|
25
|
-
exclude_file?(File.expand_path(file))
|
26
|
-
end
|
27
|
-
|
28
|
-
def include_file?(file)
|
29
|
-
!exclude_file?(file)
|
30
|
-
end
|
31
|
-
|
32
|
-
def exclude_file?(file)
|
33
|
-
with_cache(file) do
|
34
|
-
!FileSystem::CommonPath.included_in?(File.expand_path(file), Delfos.application_directories)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def reset!
|
39
|
-
@cache = nil
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def with_cache(key)
|
45
|
-
cache.include?(key) ? cache[key] : cache[key] = yield
|
46
|
-
end
|
47
|
-
|
48
|
-
def cache
|
49
|
-
@cache ||= {}
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|