rshade 0.1.9.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile +6 -2
  4. data/Gemfile.lock +10 -1
  5. data/README.md +19 -3
  6. data/Rakefile +5 -3
  7. data/bin/console +4 -3
  8. data/lib/rshade/config/registry.rb +47 -0
  9. data/lib/rshade/config/stack_store.rb +58 -0
  10. data/lib/rshade/config/store.rb +6 -5
  11. data/lib/rshade/config.rb +4 -3
  12. data/lib/rshade/core_extensions/object/reveal.rb +34 -5
  13. data/lib/rshade/event.rb +15 -5
  14. data/lib/rshade/event_observer.rb +3 -1
  15. data/lib/rshade/event_processor.rb +12 -11
  16. data/lib/rshade/event_tree.rb +13 -15
  17. data/lib/rshade/filter/abstract_filter.rb +3 -1
  18. data/lib/rshade/filter/default.rb +3 -1
  19. data/lib/rshade/filter/exclude_path_filter.rb +5 -3
  20. data/lib/rshade/filter/filter_builder.rb +14 -3
  21. data/lib/rshade/filter/filter_composition.rb +26 -24
  22. data/lib/rshade/filter/include_path_filter.rb +5 -1
  23. data/lib/rshade/filter/variable_filter.rb +4 -1
  24. data/lib/rshade/formatter/stack/json.rb +51 -0
  25. data/lib/rshade/formatter/stack/stdout.rb +13 -0
  26. data/lib/rshade/formatter/stack/string.rb +41 -0
  27. data/lib/rshade/formatter/trace/file.rb +33 -0
  28. data/lib/rshade/formatter/trace/html.rb +38 -0
  29. data/lib/rshade/formatter/trace/json.rb +61 -0
  30. data/lib/rshade/formatter/trace/stdout.rb +14 -0
  31. data/lib/rshade/formatter/trace/string.rb +48 -0
  32. data/lib/rshade/rspec/rspec.rb +7 -6
  33. data/lib/rshade/serializer/traversal.rb +16 -9
  34. data/lib/rshade/stack.rb +26 -0
  35. data/lib/rshade/stack_frame.rb +60 -0
  36. data/lib/rshade/trace.rb +7 -4
  37. data/lib/rshade/trace_observable.rb +5 -0
  38. data/lib/rshade/version.rb +3 -1
  39. data/lib/rshade.rb +25 -8
  40. data/rshade.gemspec +24 -21
  41. metadata +43 -8
  42. data/lib/rshade/formatter/file.rb +0 -28
  43. data/lib/rshade/formatter/html.rb +0 -33
  44. data/lib/rshade/formatter/json.rb +0 -59
  45. data/lib/rshade/formatter/stdout.rb +0 -10
  46. data/lib/rshade/formatter/string.rb +0 -36
data/lib/rshade.rb CHANGED
@@ -1,10 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'colorized_string'
4
+ require 'binding_of_caller'
2
5
  require 'erb'
3
6
  require 'weakref'
4
- require 'set'
5
7
  require 'observer'
6
- require 'rshade/config'
7
- require 'rshade/config/store'
8
+ require 'json'
9
+ require 'singleton'
10
+
8
11
  require 'rshade/serializer/traversal'
9
12
  require 'rshade/event_tree'
10
13
  require 'rshade/event_processor'
@@ -17,14 +20,28 @@ require 'rshade/filter/include_path_filter'
17
20
  require 'rshade/filter/exclude_path_filter'
18
21
  require 'rshade/filter/variable_filter'
19
22
  require 'rshade/filter/default'
20
- require 'rshade/formatter/string'
21
- require 'rshade/formatter/json'
22
- require 'rshade/formatter/file'
23
- require 'rshade/formatter/html'
24
- require 'rshade/formatter/stdout'
23
+
24
+ require 'rshade/formatter/trace/string'
25
+ require 'rshade/formatter/trace/json'
26
+ require 'rshade/formatter/trace/file'
27
+ require 'rshade/formatter/trace/html'
28
+ require 'rshade/formatter/trace/stdout'
29
+
30
+ require 'rshade/formatter/stack/string'
31
+ require 'rshade/formatter/stack/stdout'
32
+ require 'rshade/formatter/stack/json'
33
+
34
+ require 'rshade/config'
35
+ require 'rshade/config/store'
36
+ require 'rshade/config/stack_store'
37
+ require 'rshade/config/registry'
38
+
25
39
  require 'rshade/event'
26
40
  require 'rshade/trace'
41
+ require 'rshade/stack'
42
+ require 'rshade/stack_frame'
27
43
  require 'rshade/rspec/rspec'
44
+ require 'rshade/core_extensions/object/reveal'
28
45
  require 'rshade/version'
29
46
 
30
47
  module RShade
data/rshade.gemspec CHANGED
@@ -1,44 +1,47 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "rshade/version"
5
+ require 'rshade/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "rshade"
8
+ spec.name = 'rshade'
8
9
  spec.version = RShade::VERSION
9
- spec.authors = ["Ivan Lopatin"]
10
- spec.email = ["gingray.dev@gmail.com"]
10
+ spec.authors = ['Ivan Lopatin']
11
+ spec.email = ['gingray.dev@gmail.com']
11
12
 
12
- spec.summary = %q{https://github.com/gingray/rshade}
13
- spec.description = %q{https://github.com/gingray/rshade}
14
- spec.homepage = "https://github.com/gingray/rshade"
15
- spec.license = "MIT"
13
+ spec.summary = 'https://github.com/gingray/rshade'
14
+ spec.description = 'https://github.com/gingray/rshade'
15
+ spec.homepage = 'https://github.com/gingray/rshade'
16
+ spec.license = 'MIT'
16
17
 
17
18
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
19
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
20
  if spec.respond_to?(:metadata)
20
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
22
 
22
- spec.metadata["homepage_uri"] = spec.homepage
23
- spec.metadata["source_code_uri"] = "https://github.com/gingray/rshade"
24
- spec.metadata["changelog_uri"] = "https://github.com/gingray/rshade/CHANGELOG.md"
23
+ spec.metadata['homepage_uri'] = spec.homepage
24
+ spec.metadata['source_code_uri'] = 'https://github.com/gingray/rshade'
25
+ spec.metadata['changelog_uri'] = 'https://github.com/gingray/rshade/CHANGELOG.md'
25
26
  else
26
- raise "RubyGems 2.0 or newer is required to protect against " \
27
- "public gem pushes."
27
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
28
+ 'public gem pushes.'
28
29
  end
29
30
 
30
31
  # Specify which files should be added to the gem when it is released.
31
32
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
33
34
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
35
  end
35
- spec.bindir = "exe"
36
+ spec.bindir = 'exe'
36
37
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
- spec.require_paths = ["lib"]
38
+ spec.require_paths = ['lib']
38
39
 
40
+ spec.add_runtime_dependency 'binding_of_caller'
39
41
  spec.add_runtime_dependency 'colorize'
42
+ spec.add_runtime_dependency 'prism'
40
43
 
41
- spec.add_development_dependency "bundler", "~> 2.2.33"
42
- spec.add_development_dependency "rake", ">= 12.3.3"
43
- spec.add_development_dependency "rspec", "~> 3.0"
44
+ spec.add_development_dependency 'bundler', '~> 2.2.33'
45
+ spec.add_development_dependency 'rake', '>= 12.3.3'
46
+ spec.add_development_dependency 'rspec', '~> 3.0'
44
47
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rshade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Lopatin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-29 00:00:00.000000000 Z
11
+ date: 2025-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: binding_of_caller
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: colorize
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - ">="
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: prism
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +114,8 @@ files:
86
114
  - html/template.html.erb
87
115
  - lib/rshade.rb
88
116
  - lib/rshade/config.rb
117
+ - lib/rshade/config/registry.rb
118
+ - lib/rshade/config/stack_store.rb
89
119
  - lib/rshade/config/store.rb
90
120
  - lib/rshade/core_extensions/object/reveal.rb
91
121
  - lib/rshade/event.rb
@@ -99,14 +129,19 @@ files:
99
129
  - lib/rshade/filter/filter_composition.rb
100
130
  - lib/rshade/filter/include_path_filter.rb
101
131
  - lib/rshade/filter/variable_filter.rb
102
- - lib/rshade/formatter/file.rb
103
- - lib/rshade/formatter/html.rb
104
- - lib/rshade/formatter/json.rb
105
- - lib/rshade/formatter/stdout.rb
106
- - lib/rshade/formatter/string.rb
132
+ - lib/rshade/formatter/stack/json.rb
133
+ - lib/rshade/formatter/stack/stdout.rb
134
+ - lib/rshade/formatter/stack/string.rb
135
+ - lib/rshade/formatter/trace/file.rb
136
+ - lib/rshade/formatter/trace/html.rb
137
+ - lib/rshade/formatter/trace/json.rb
138
+ - lib/rshade/formatter/trace/stdout.rb
139
+ - lib/rshade/formatter/trace/string.rb
107
140
  - lib/rshade/rails/rails.rb
108
141
  - lib/rshade/rspec/rspec.rb
109
142
  - lib/rshade/serializer/traversal.rb
143
+ - lib/rshade/stack.rb
144
+ - lib/rshade/stack_frame.rb
110
145
  - lib/rshade/trace.rb
111
146
  - lib/rshade/trace_observable.rb
112
147
  - lib/rshade/version.rb
@@ -136,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
171
  - !ruby/object:Gem::Version
137
172
  version: '0'
138
173
  requirements: []
139
- rubygems_version: 3.0.8
174
+ rubygems_version: 3.4.10
140
175
  signing_key:
141
176
  specification_version: 4
142
177
  summary: https://github.com/gingray/rshade
@@ -1,28 +0,0 @@
1
- module RShade
2
- module Formatter
3
- class File
4
- attr_reader :formatter
5
- FILE_NAME = 'stacktrace.json'.freeze
6
-
7
- def initialize(args={})
8
- @formatter = args.fetch(:format, Json)
9
- end
10
-
11
- # @param [RShade::EventProcessor] event_store
12
- def call(event_store)
13
- data = formatter.call(event_store)
14
- if formatter == Json
15
- write_to_file(JSON.pretty_generate(data))
16
- else
17
- write_to_file(data.to_s)
18
- end
19
- end
20
-
21
- def write_to_file(data)
22
- ::File.open(::File.join(RShade::Config.store_dir, FILE_NAME), "w+") do |f|
23
- f.write data
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,33 +0,0 @@
1
- require 'json'
2
-
3
- module RShade
4
- module Formatter
5
- class Html
6
- attr_reader :formatter
7
- FILE_NAME = 'stacktrace.html'.freeze
8
- TEMPLATE = 'html/template.html.erb'
9
-
10
- def initialize(args={})
11
- @formatter = args.fetch(:formatter, Json)
12
- end
13
-
14
- # @param [RShade::EventProcessor] event_store
15
- def call(event_store)
16
- data = formatter.call(event_store)
17
- erb_template = ERB.new(template)
18
- content = erb_template.result_with_hash({json: data.to_json})
19
- write_to_file(content)
20
- end
21
-
22
- def write_to_file(data)
23
- ::File.open(::File.join(RShade::Config.store_dir, FILE_NAME), "w+") do |f|
24
- f.write data
25
- end
26
- end
27
-
28
- def template
29
- @template ||=::File.read(::File.join(::RShade::Config.root_dir, TEMPLATE))
30
- end
31
- end
32
- end
33
- end
@@ -1,59 +0,0 @@
1
- module RShade
2
- module Formatter
3
- class Json
4
- attr_reader :event_processor
5
-
6
- # @param [RShade::EventProcessor] event_store
7
- def call(event_store)
8
- @event_store = event_store
9
- flat
10
- end
11
-
12
- def flat
13
- arr = []
14
- event_store.each do |node|
15
- arr << item(node.event)
16
- end
17
- arr.sort_by { |item| item[:level]}
18
- end
19
-
20
- def hierarchical
21
- hash = {}
22
- event_store.each do |node|
23
- depth = node.level
24
- ref = hash_iterate(hash, depth)
25
- ref[:data] = item(node)
26
- end
27
- sort_hash(hash)
28
- end
29
-
30
- def sort_hash(h)
31
- {}.tap do |h2|
32
- h.sort.each do |k,v|
33
- h2[k] = v.is_a?(Hash) ? sort_hash(v) : v
34
- end
35
- end
36
- end
37
-
38
- def hash_iterate(hash, depth)
39
- (0..depth).each do |lvl|
40
- unless hash[:inner]
41
- hash[:inner] = {}
42
- end
43
- hash = hash[:inner]
44
- end
45
- hash
46
- end
47
-
48
- def item(value)
49
- {
50
- class: value.klass.to_s,
51
- method_name: value.method_name,
52
- full_path: "#{value.path}:#{value.lineno}",
53
- level: value.depth,
54
- vars: value.vars
55
- }
56
- end
57
- end
58
- end
59
- end
@@ -1,10 +0,0 @@
1
- module RShade
2
- module Formatter
3
- class Stdout < String
4
- # @param [RShade::EventProcessor] event_store
5
- def call(event_store)
6
- puts super(event_store)
7
- end
8
- end
9
- end
10
- end
@@ -1,36 +0,0 @@
1
- module RShade
2
- module Formatter
3
- class String
4
- ROOT_SEP = "---\n"
5
-
6
- def initialize(opts= {})
7
- end
8
-
9
- # @param [RShade::EventProcessor] event_store
10
- def call(event_store)
11
- buffer = StringIO.new
12
- event_store.each_with_index do |node, idx|
13
- depth = node.level
14
- event = node.value
15
- if depth == 1
16
- buffer << ROOT_SEP
17
- next
18
- end
19
- next unless event
20
- buffer.write line(idx, event, node.vlevel)
21
- end
22
- buffer.string
23
- end
24
-
25
- def line(line_idx, value, depth)
26
- vars = value.vars
27
- returned = ColorizedString["=> |#{value.return_value}|"].colorize(:magenta)
28
-
29
- class_method = ColorizedString["#{value.klass}##{value.method_name}"].colorize(:green)
30
- full_path = ColorizedString["#{value.path}:#{value.lineno}"].colorize(:blue)
31
- line_idx = ColorizedString["[#{line_idx}] "].colorize(:red)
32
- "#{' ' * depth}#{line_idx}#{class_method}(#{vars}) #{returned} -> #{full_path}\n"
33
- end
34
- end
35
- end
36
- end