rshade 0.1.9.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.rubocop.yml +31 -0
  4. data/Gemfile +9 -2
  5. data/Gemfile.lock +11 -2
  6. data/README.md +20 -3
  7. data/Rakefile +5 -3
  8. data/bin/console +4 -3
  9. data/lib/rshade/config/registry.rb +40 -0
  10. data/lib/rshade/config/stack_store.rb +63 -0
  11. data/lib/rshade/config/store.rb +12 -7
  12. data/lib/rshade/config.rb +8 -7
  13. data/lib/rshade/core_extensions/object/reveal.rb +37 -5
  14. data/lib/rshade/event.rb +15 -5
  15. data/lib/rshade/event_observer.rb +3 -1
  16. data/lib/rshade/event_processor.rb +12 -11
  17. data/lib/rshade/event_tree.rb +18 -18
  18. data/lib/rshade/filter/abstract_filter.rb +3 -1
  19. data/lib/rshade/filter/default.rb +4 -2
  20. data/lib/rshade/filter/exclude_path_filter.rb +5 -3
  21. data/lib/rshade/filter/filter_builder.rb +14 -3
  22. data/lib/rshade/filter/filter_composition.rb +29 -25
  23. data/lib/rshade/filter/include_path_filter.rb +6 -1
  24. data/lib/rshade/filter/variable_filter.rb +5 -1
  25. data/lib/rshade/formatter/stack/json.rb +51 -0
  26. data/lib/rshade/formatter/stack/stdout.rb +13 -0
  27. data/lib/rshade/formatter/stack/string.rb +53 -0
  28. data/lib/rshade/formatter/trace/file.rb +31 -0
  29. data/lib/rshade/formatter/trace/html.rb +36 -0
  30. data/lib/rshade/formatter/trace/json.rb +60 -0
  31. data/lib/rshade/formatter/trace/stdout.rb +14 -0
  32. data/lib/rshade/formatter/trace/string.rb +48 -0
  33. data/lib/rshade/rspec/rspec.rb +8 -5
  34. data/lib/rshade/serializer/traversal.rb +10 -8
  35. data/lib/rshade/stack.rb +26 -0
  36. data/lib/rshade/stack_frame.rb +61 -0
  37. data/lib/rshade/trace.rb +7 -4
  38. data/lib/rshade/trace_observable.rb +10 -5
  39. data/lib/rshade/version.rb +3 -1
  40. data/lib/rshade.rb +25 -8
  41. data/rshade.gemspec +24 -22
  42. metadata +29 -35
  43. data/lib/rshade/formatter/file.rb +0 -28
  44. data/lib/rshade/formatter/html.rb +0 -33
  45. data/lib/rshade/formatter/json.rb +0 -59
  46. data/lib/rshade/formatter/stdout.rb +0 -10
  47. data/lib/rshade/formatter/string.rb +0 -36
  48. data/lib/rshade/rails/rails.rb +0 -0
data/lib/rshade/trace.rb CHANGED
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RShade
2
4
  class Trace
3
5
  attr_reader :config, :event_store
4
-
6
+
5
7
  # @param [RShade::Config,RShade::Config::Store] config
6
8
  def initialize(config)
7
9
  @config = fetch_config(config)
8
10
  @event_store = EventTree.new
9
11
  end
10
12
 
11
- def self.reveal(config=nil, &block)
13
+ def self.reveal(config = nil, &block)
12
14
  new(config).reveal(&block)
13
15
  end
14
16
 
@@ -16,7 +18,7 @@ module RShade
16
18
  processor = EventProcessor.new(event_store, config)
17
19
  observer = EventObserver.new(config, processor)
18
20
  observable = RShade::TraceObservable.new([observer], config)
19
- observable.reveal &block
21
+ observable.reveal(&block)
20
22
  self
21
23
  end
22
24
 
@@ -25,8 +27,9 @@ module RShade
25
27
  end
26
28
 
27
29
  private
30
+
28
31
  def fetch_config(config)
29
- config = config || ::RShade::Config.default
32
+ config ||= ::RShade::Config.default
30
33
  config = config.value if config.is_a?(::RShade::Config)
31
34
  config
32
35
  end
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RShade
2
4
  class TraceObservable
3
5
  include Observable
4
6
  attr_reader :trace_p
7
+
5
8
  CALL_EVENTS = Set[:call, :c_call, :b_call]
6
9
  RETURN_EVENTS = Set[:return, :c_return, :b_return]
7
10
 
@@ -27,13 +30,15 @@ module RShade
27
30
  end
28
31
 
29
32
  private
33
+
30
34
  # more info https://rubyapi.org/3.1/o/tracepoint
31
- # @param [TracePoint] tp
32
- def process(tp)
35
+ # @param [TracePoint] trace_point
36
+ def process(trace_point)
33
37
  changed
34
- event = Event.from_trace_point(tp)
35
- return notify_observers(event, :enter) if CALL_EVENTS.include?(tp.event)
36
- return notify_observers(event, :leave) if RETURN_EVENTS.include?(tp.event)
38
+ event = Event.from_trace_point(trace_point)
39
+ return notify_observers(event, :enter) if CALL_EVENTS.include?(trace_point.event)
40
+ return notify_observers(event, :leave) if RETURN_EVENTS.include?(trace_point.event)
41
+
37
42
  notify_observers(event, :other)
38
43
  end
39
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RShade
2
- VERSION = "0.1.9.1"
4
+ VERSION = '0.2.1'
3
5
  end
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,46 @@
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']
39
+ spec.required_ruby_version = '>= 2.7.0'
38
40
 
39
- spec.add_runtime_dependency 'colorize'
41
+ spec.add_dependency 'binding_of_caller'
42
+ spec.add_dependency 'colorize'
43
+ spec.add_dependency 'prism'
40
44
 
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"
45
+ spec.metadata['rubygems_mfa_required'] = 'true'
44
46
  end
metadata CHANGED
@@ -1,17 +1,17 @@
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.1
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
13
  - !ruby/object:Gem::Dependency
14
- name: colorize
14
+ name: binding_of_caller
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,47 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 2.2.33
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 2.2.33
41
- - !ruby/object:Gem::Dependency
42
- name: rake
28
+ name: colorize
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: 12.3.3
48
- type: :development
33
+ version: '0'
34
+ type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: 12.3.3
40
+ version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
- name: rspec
42
+ name: prism
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - "~>"
45
+ - - ">="
60
46
  - !ruby/object:Gem::Version
61
- version: '3.0'
62
- type: :development
47
+ version: '0'
48
+ type: :runtime
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - "~>"
52
+ - - ">="
67
53
  - !ruby/object:Gem::Version
68
- version: '3.0'
54
+ version: '0'
69
55
  description: https://github.com/gingray/rshade
70
56
  email:
71
57
  - gingray.dev@gmail.com
@@ -75,6 +61,7 @@ extra_rdoc_files: []
75
61
  files:
76
62
  - ".gitignore"
77
63
  - ".rspec"
64
+ - ".rubocop.yml"
78
65
  - ".travis.yml"
79
66
  - Gemfile
80
67
  - Gemfile.lock
@@ -86,6 +73,8 @@ files:
86
73
  - html/template.html.erb
87
74
  - lib/rshade.rb
88
75
  - lib/rshade/config.rb
76
+ - lib/rshade/config/registry.rb
77
+ - lib/rshade/config/stack_store.rb
89
78
  - lib/rshade/config/store.rb
90
79
  - lib/rshade/core_extensions/object/reveal.rb
91
80
  - lib/rshade/event.rb
@@ -99,14 +88,18 @@ files:
99
88
  - lib/rshade/filter/filter_composition.rb
100
89
  - lib/rshade/filter/include_path_filter.rb
101
90
  - 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
107
- - lib/rshade/rails/rails.rb
91
+ - lib/rshade/formatter/stack/json.rb
92
+ - lib/rshade/formatter/stack/stdout.rb
93
+ - lib/rshade/formatter/stack/string.rb
94
+ - lib/rshade/formatter/trace/file.rb
95
+ - lib/rshade/formatter/trace/html.rb
96
+ - lib/rshade/formatter/trace/json.rb
97
+ - lib/rshade/formatter/trace/stdout.rb
98
+ - lib/rshade/formatter/trace/string.rb
108
99
  - lib/rshade/rspec/rspec.rb
109
100
  - lib/rshade/serializer/traversal.rb
101
+ - lib/rshade/stack.rb
102
+ - lib/rshade/stack_frame.rb
110
103
  - lib/rshade/trace.rb
111
104
  - lib/rshade/trace_observable.rb
112
105
  - lib/rshade/version.rb
@@ -121,6 +114,7 @@ metadata:
121
114
  homepage_uri: https://github.com/gingray/rshade
122
115
  source_code_uri: https://github.com/gingray/rshade
123
116
  changelog_uri: https://github.com/gingray/rshade/CHANGELOG.md
117
+ rubygems_mfa_required: 'true'
124
118
  post_install_message:
125
119
  rdoc_options: []
126
120
  require_paths:
@@ -129,14 +123,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
123
  requirements:
130
124
  - - ">="
131
125
  - !ruby/object:Gem::Version
132
- version: '0'
126
+ version: 2.7.0
133
127
  required_rubygems_version: !ruby/object:Gem::Requirement
134
128
  requirements:
135
129
  - - ">="
136
130
  - !ruby/object:Gem::Version
137
131
  version: '0'
138
132
  requirements: []
139
- rubygems_version: 3.0.8
133
+ rubygems_version: 3.4.10
140
134
  signing_key:
141
135
  specification_version: 4
142
136
  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
File without changes