rshade 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf8737edb621544556bb58751c0513b17fe1d9f47a6d36fc77c57cac7cb00ef4
4
- data.tar.gz: 13beabd1a6b22e62efc8c4bec6d0a7931ddd2960b8a4ec9cf0eeac6c0c2b8b95
3
+ metadata.gz: c22edeb524363703e1593cc552713c7e9cef6203ab2df81d1c52ce1d39b8e68f
4
+ data.tar.gz: ac8080bc18e8c4ef3ebe9274815c35cbbd201cc210791c914f366786648f07e7
5
5
  SHA512:
6
- metadata.gz: d2e84b206dc81d4dad3af68cee691f22ec65749de2971ba5ec4c6001187333a17ea2e36c42cdb8341605cfbbbbc459add8355af29fc097e2108b96eb5c9e233c
7
- data.tar.gz: cd41a6538fad5193dfcf4888da29ba1bfc0e216a5d2023e47291425546d8633660af24cffbd196960d6896e4b2b077ff549f4a57392164b8b625a54b90947f66
6
+ metadata.gz: e8803cd8aa9df51f749d3e68ec9a8bb86aad01d731ce69b69862f5d105fea6297c8933092b20a66a1f3a2fd62a762da11b765e4c944cd9ccd6e65a88a7483168
7
+ data.tar.gz: 637c5715a9404d2e491919f32658ac499027d39cf85c126a804f6b44f5a15aa0bc469483deae67f7516f3735bd873c450105baae34a3d042c6428ed815cfe9b6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rshade (0.1.2)
4
+ rshade (0.1.3)
5
5
  colorize
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,10 +1,8 @@
1
1
  # RShade
2
-
3
2
 
4
3
  ![warcraft shade](https://github.com/gingray/rshade/raw/master/shade.jpg)
5
4
 
6
- Ruby Shade or RShade gem to help you to reveal which code are used in program execution.
7
-
5
+ Ruby Shade or RShade gem to help you to reveal what lines of code are used in program execution.
8
6
 
9
7
  ```ruby
10
8
  trace = RShade::Trace.new
@@ -18,6 +16,26 @@ trace.show
18
16
  end
19
17
 
20
18
  ```
19
+ ## Example
20
+ I've took example from https://github.com/spree/spree code base. Wrap code to take a look what code is in use when you save variant.
21
+ On such huge codebase as spree it's helpful to know what callbacks are triggered and so on.
22
+ ```ruby
23
+ context '#cost_currency' do
24
+ context 'when cost currency is nil' do
25
+ before { variant.cost_currency = nil }
26
+
27
+ it 'populates cost currency with the default value on save', focus: true do
28
+ rshade_reveal do
29
+ variant.save!
30
+ end
31
+ expect(variant.cost_currency).to eql 'USD'
32
+ end
33
+ end
34
+ end
35
+ ```
36
+ Below is example how output will look like.
37
+ As you can see all code that have been in use is printed.
38
+ [![asciicast](https://asciinema.org/a/MR5KL7TmHmYRUhwBUWQjBI373.svg)](https://asciinema.org/a/MR5KL7TmHmYRUhwBUWQjBI373)
21
39
 
22
40
  ## Installation
23
41
 
@@ -27,23 +45,13 @@ Add this line to your application's Gemfile:
27
45
  gem 'rshade'
28
46
  ```
29
47
 
30
- And then execute:
31
-
32
- $ bundle
33
- Or install it yourself as:
34
-
35
- $ gem install rshade
36
- ## Usage
37
-
38
- TODO: Write usage instructions here
39
-
40
48
  ## TODO
41
49
  Use stack to keep connections between current method and caller
42
50
  take a look on https://github.com/matugm/visual-call-graph
43
51
 
44
52
  ## Contributing
45
53
 
46
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rshade.
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gingray/rshade.
47
55
 
48
56
  ## License
49
57
 
data/lib/rshade/source.rb CHANGED
@@ -31,6 +31,10 @@ module RShade
31
31
  @hash[:method_name]
32
32
  end
33
33
 
34
+ def vars
35
+ @hash[:vars]
36
+ end
37
+
34
38
  def exclude_path
35
39
  @path_arr ||= begin
36
40
  [ENV['GEM_PATH'].split(':'), parse_ruby_version].flatten.compact
@@ -47,7 +51,7 @@ module RShade
47
51
  def pretty
48
52
  class_method = "#{klass}##{method_name}".colorize(:green)
49
53
  full_path = "#{path}:#{lineno}".colorize(:blue)
50
- "#{class_method} -> #{full_path}"
54
+ "#{class_method}(#{vars.to_json}) -> #{full_path}"
51
55
  end
52
56
  end
53
57
  end
data/lib/rshade/trace.rb CHANGED
@@ -50,14 +50,20 @@ module RShade
50
50
  def process_trace(tp)
51
51
  if tp.event == :call
52
52
  parent = @stack.last
53
- hash = { level: @stack.size, path: tp.path, lineno: tp.lineno, klass: tp.defined_class, method_name: tp.method_id }
53
+ vars = {}
54
+ tp.binding.local_variables.each do |var|
55
+ vars[var] = tp.binding.local_variable_get var
56
+ end
57
+ hash = { level: @stack.size, path: tp.path, lineno: tp.lineno, klass: tp.defined_class, method_name: tp.method_id, vars: vars }
54
58
  node = SourceNode.new(Source.new(hash))
55
59
  node.parent = parent
56
60
  parent << node
57
61
  @stack.push node
58
62
  end
59
63
 
60
- @stack.pop if tp.event == :return && @stack.size > 1
64
+ if tp.event == :return && @stack.size > 1
65
+ @stack.pop
66
+ end
61
67
  end
62
68
  end
63
69
  end
@@ -1,3 +1,3 @@
1
1
  module RShade
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rshade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Lopatin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-02 00:00:00.000000000 Z
11
+ date: 2019-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize