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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/delfos.rb +72 -13
  3. data/lib/delfos/call_stack.rb +9 -9
  4. data/lib/delfos/call_stack/stack.rb +18 -18
  5. data/lib/delfos/file_system.rb +16 -0
  6. data/lib/delfos/file_system/app_directories.rb +42 -0
  7. data/lib/delfos/file_system/common_path.rb +17 -11
  8. data/lib/delfos/file_system/distance_calculation.rb +12 -3
  9. data/lib/delfos/file_system/path_determination.rb +4 -1
  10. data/lib/delfos/file_system/relation.rb +1 -0
  11. data/lib/delfos/method_trace.rb +59 -0
  12. data/lib/delfos/method_trace/call_handler.rb +48 -0
  13. data/lib/delfos/method_trace/code_location.rb +35 -0
  14. data/lib/delfos/method_trace/code_location/call_site.rb +38 -0
  15. data/lib/delfos/method_trace/code_location/container_method_factory.rb +71 -0
  16. data/lib/delfos/method_trace/code_location/eval_in_caller.rb +17 -0
  17. data/lib/delfos/method_trace/code_location/filename_helpers.rb +46 -0
  18. data/lib/delfos/method_trace/code_location/method.rb +58 -0
  19. data/lib/delfos/neo4j.rb +4 -4
  20. data/lib/delfos/neo4j/batch/execution.rb +30 -88
  21. data/lib/delfos/neo4j/batch/retryable.rb +101 -0
  22. data/lib/delfos/neo4j/call_site_query.rb +89 -0
  23. data/lib/delfos/neo4j/distance/call_site_fetcher.rb +1 -0
  24. data/lib/delfos/neo4j/distance/update.rb +22 -5
  25. data/lib/delfos/neo4j/live/call_site_logger.rb +17 -0
  26. data/lib/delfos/neo4j/offline/call_site_logger.rb +39 -0
  27. data/lib/delfos/neo4j/offline/importer.rb +68 -0
  28. data/lib/delfos/neo4j/query_execution/errors.rb +13 -3
  29. data/lib/delfos/neo4j/query_execution/http.rb +1 -0
  30. data/lib/delfos/neo4j/query_execution/http_query.rb +20 -15
  31. data/lib/delfos/neo4j/query_execution/sync.rb +1 -0
  32. data/lib/delfos/neo4j/query_execution/transactional.rb +24 -13
  33. data/lib/delfos/neo4j/schema.rb +5 -19
  34. data/lib/delfos/setup.rb +76 -44
  35. metadata +77 -18
  36. data/lib/delfos/method_logging.rb +0 -52
  37. data/lib/delfos/method_logging/call_site_parsing.rb +0 -74
  38. data/lib/delfos/method_logging/code_location.rb +0 -89
  39. data/lib/delfos/method_logging/method_parameters.rb +0 -53
  40. data/lib/delfos/neo4j/call_stack_query.rb +0 -88
  41. data/lib/delfos/neo4j/informer.rb +0 -128
  42. data/lib/delfos/patching/basic_object.rb +0 -14
  43. data/lib/delfos/patching/basic_object_remove.rb +0 -7
  44. data/lib/delfos/patching/method_cache.rb +0 -83
  45. data/lib/delfos/patching/method_override.rb +0 -148
  46. data/lib/delfos/patching/module_defining_methods.rb +0 -105
  47. 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
 
@@ -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.flush!(commit_url)
16
- response = Http.new(commit_url).post({ statements: [] }.to_json)
16
+ def self.commit!(url)
17
+ response = Http.new(url).post({ statements: [] }.to_json)
17
18
 
18
- check_for_error(commit_url, response)
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
- self.class.check_for_error(uri, response)
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
@@ -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
- error "-" * 80
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
- if response.code == "200"
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
- private
51
+ JSON.parse response.body
52
+ end
67
53
 
68
54
  def constraints_uri
69
55
  Delfos.neo4j.uri_for("/db/data/schema/constraint")
@@ -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, application_directories: nil)
8
- self.application_directories = application_directories
9
- self.call_site_logger = call_site_logger
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
- perform_patching!
16
+ require "delfos/method_trace"
17
+ ::Delfos::MethodTrace.trace!
12
18
  end
13
19
 
14
20
  def application_directories=(dirs)
15
- dirs ||= %w(app lib)
21
+ dirs ||= %w[app lib]
16
22
  require "pathname"
17
- Delfos.application_directories = Array(dirs).map { |f| Pathname.new(File.expand_path(f.to_s)) }
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
- @call_site_logger = call_site_logger || default_call_site_logger
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.setup_neo4j!
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
- require "delfos/neo4j/informer"
32
- Delfos:: Neo4j::Informer.new
52
+ def disable_tracepoint!
53
+ require "delfos/method_trace"
54
+ ::Delfos::MethodTrace.disable!
33
55
  end
34
56
 
35
- def reset!
36
- if defined? Delfos::CallStack
37
- Delfos::CallStack.pop_until_top!
38
- Delfos::CallStack.reset!
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
- if defined? Delfos::Neo4j::Batch::Execution
67
+ ignoring_undefined "Delfos::Neo4j::Batch::Retryable" do |b|
42
68
  begin
43
- Delfos::Neo4j::Batch::Execution.flush!
44
- rescue
45
- Delfos::Neo4j::QueryExecution::ExpiredTransaction
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
- # unstubbing depends upon MethodCache being still defined
52
- # so this order is important
53
- unstub_all!
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
- @call_site_logger = nil
87
+ Delfos.max_query_size = nil
65
88
  Delfos.neo4j = nil
66
89
  end
67
90
 
68
- def unstub_all!
69
- return unless defined? Delfos::Patching::Unstubber
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
- Delfos::Patching::Unstubber.unstub_all!
101
+ def with_rescue
102
+ yield
103
+ rescue Delfos::Neo4j::QueryExecution::ExpiredTransaction
104
+ puts # no-op
72
105
  end
73
106
 
74
- def remove_cached_methods!
75
- return unless defined? Delfos::Patching::MethodCache
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::Patching::MethodCache.reset!
111
+ Delfos.offline_query_filename = filename_from(offline_query_saving)
78
112
  end
79
113
 
80
- def remove_patching!
81
- load "delfos/patching/basic_object_remove.rb"
82
- end
114
+ def filename_from(offline_query_saving)
115
+ return offline_query_saving if offline_query_saving.is_a?(String)
83
116
 
84
- def perform_patching!
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.1
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: 2016-12-29 00:00:00.000000000 Z
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/method_logging.rb
123
- - lib/delfos/method_logging/call_site_parsing.rb
124
- - lib/delfos/method_logging/code_location.rb
125
- - lib/delfos/method_logging/method_parameters.rb
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/call_stack_query.rb
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/informer.rb
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: '0'
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: '0'
222
+ version: 1.3.1
164
223
  requirements: []
165
224
  rubyforge_project:
166
- rubygems_version: 2.5.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