rshade 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f1a648fd8621c8dfe519955fc273f5a22314a8e2a6fb372296e4694f11ed6db6
4
+ data.tar.gz: 9d7f218e95562c710111e7fcfd95f528c61d808dbcc5bab044de559565e2be52
5
+ SHA512:
6
+ metadata.gz: 786170c5c9181173d21177c709ce58844d2cae4d500c1cbb8542eb58e51e43195bebebb3567dffabd5d97fe95d052235215f97b2d8c90e2997fb068d8c292282
7
+ data.tar.gz: 8df21732b47f6a15ffb38ea09c1dfe5755e6df65b5552c9721a0d509267dbd4e29c33cf63fd0a11c1949c07a2ee2bd283708dd6f9c7dfcd280387bc4720ab67d
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.6
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rshade.gemspec
6
+ gemspec
7
+
8
+ group :development, :test do
9
+ gem 'pry'
10
+ end
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rshade (0.1.0)
5
+ colorize
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ colorize (0.8.1)
12
+ diff-lcs (1.3)
13
+ method_source (0.9.2)
14
+ pry (0.12.2)
15
+ coderay (~> 1.1.0)
16
+ method_source (~> 0.9.0)
17
+ rake (10.5.0)
18
+ rspec (3.8.0)
19
+ rspec-core (~> 3.8.0)
20
+ rspec-expectations (~> 3.8.0)
21
+ rspec-mocks (~> 3.8.0)
22
+ rspec-core (3.8.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-expectations (3.8.3)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-mocks (3.8.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-support (3.8.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 1.16)
37
+ pry
38
+ rake (~> 10.0)
39
+ rshade!
40
+ rspec (~> 3.0)
41
+
42
+ BUNDLED WITH
43
+ 1.16.6
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Ivan Lopatin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # RShade
2
+
3
+
4
+ ![warcraft shade](https://github.com/gingray/rshade/raw/master/shade.jpg)
5
+
6
+ Ruby Shade or RShade gem to help you to reveal which code are used in program execution.
7
+
8
+
9
+ ```ruby
10
+ trace = RShade::Trace.new
11
+ trace.reveal do
12
+ #your code here
13
+ end
14
+ ```
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'rshade'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+ Or install it yourself as:
28
+
29
+ $ gem install rshade
30
+ ## Usage
31
+
32
+ TODO: Write usage instructions here
33
+
34
+ ## TODO
35
+ Use stack to keep connections between current method and caller
36
+ take a look on https://github.com/matugm/visual-call-graph
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rshade.
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rshade"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ require 'colorize'
2
+ require "rshade/helper"
3
+ require "rshade/source_node"
4
+ require "rshade/filter"
5
+ require "rshade/trace"
6
+ require "rshade/rspec"
7
+ require "rshade/version"
8
+
9
+ module RShade
10
+ end
@@ -0,0 +1,23 @@
1
+ module RShade
2
+ class Filter
3
+ RUBY_VERSION_PATTERN = /ruby-[0-9.]*/
4
+ def call(path)
5
+ return false unless path
6
+
7
+ exclude_path.none? { |item| path.include? item }
8
+ end
9
+
10
+ def exclude_path
11
+ @path_arr ||= begin
12
+ [ENV['GEM_PATH'].split(':'), parse_ruby_version].flatten.compact
13
+ end
14
+ end
15
+
16
+ def parse_ruby_version
17
+ val = RUBY_VERSION_PATTERN.match(ENV['GEM_PATH'])
18
+ return nil unless val
19
+
20
+ val[0]
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ module RShade
2
+ module Helper
3
+ def pretty_print(root)
4
+ str = StringIO.new
5
+ str.write "\n\n"
6
+ str.write "---\n".colorize(:yellow)
7
+ root.traverse do |node|
8
+ str.write"#{' ' * node.level}#{node.pretty}\n" if node.valid?
9
+ end
10
+ str.write '---'.colorize(:yellow)
11
+ str.string
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ module RShade
2
+ REPORTS = []
3
+
4
+ module RSpecHelper
5
+ def rshade_reveal(&block)
6
+ raise 'No block given' unless block_given?
7
+
8
+ trace = Trace.new
9
+ trace.reveal do
10
+ yield
11
+ end
12
+
13
+ REPORTS.push trace.show
14
+ end
15
+ end
16
+ end
17
+
18
+ if defined? RSpec
19
+ RSpec.configure do |c|
20
+ c.include RShade::RSpecHelper
21
+
22
+ c.after(:suite) do
23
+ RShade::REPORTS.each(&method(:puts))
24
+ RShade::REPORTS.clear
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,69 @@
1
+ module RShade
2
+ class SourceNode
3
+ attr_accessor :nodes, :value, :parent
4
+
5
+ def initialize(parent, value = nil)
6
+ @nodes = []
7
+ @value = value || { valid: true, level: 0 }
8
+ @value[:valid] = true unless @value.has_key?(:valid)
9
+ @parent = parent
10
+ end
11
+
12
+ def add(node)
13
+ @nodes << node
14
+ end
15
+
16
+ def valid?
17
+ @value[:valid]
18
+ end
19
+
20
+ def toggle_valid(state)
21
+ @value[:valid] = state
22
+ end
23
+
24
+ def level
25
+ @value[:level] || 0
26
+ end
27
+
28
+ def klass
29
+ @value[:klass]
30
+ end
31
+
32
+ def method_name
33
+ @value[:method_name]
34
+ end
35
+
36
+ def path
37
+ @value[:path]
38
+ end
39
+
40
+ def lineno
41
+ @value[:lineno]
42
+ end
43
+
44
+ def pretty
45
+ class_method = "#{klass}##{method_name}".colorize(:green)
46
+ full_path = "#{path}:#{lineno}".colorize(:blue)
47
+ "#{class_method} -> #{full_path}"
48
+ end
49
+
50
+ def filter(node = self, &block)
51
+ return unless block_given?
52
+
53
+ node.nodes.each do |item|
54
+ filter(item, &block)
55
+ end
56
+
57
+ unless yield(node)
58
+ node.toggle_valid false
59
+ end
60
+ end
61
+
62
+ def traverse(node = self, &block)
63
+ return unless block_given?
64
+
65
+ yield(node)
66
+ node.nodes.each { |leaf| traverse(leaf, &block) }
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,44 @@
1
+ module RShade
2
+ class Trace
3
+ include RShade::Helper
4
+ attr_accessor :source_tree, :open, :close, :set
5
+ EVENTS = %i[call return].freeze
6
+
7
+ def initialize
8
+ @source_tree = SourceNode.new(nil)
9
+ @tp = TracePoint.new(*EVENTS, &method(:process_trace))
10
+ @filter = RShade::Filter.new
11
+ @stack = [@source_tree]
12
+ end
13
+
14
+ def reveal
15
+ return unless block_given?
16
+
17
+ @tp.enable
18
+ yield
19
+ ensure
20
+ @tp.disable
21
+ end
22
+
23
+ def show
24
+ @source_tree.filter do |node|
25
+ next true unless node.parent
26
+
27
+ @filter.call(node.path)
28
+ end
29
+ pretty_print @source_tree
30
+ end
31
+
32
+ def process_trace(tp)
33
+ if tp.event == :call
34
+ parent = @stack.last
35
+ hash = { level: @stack.size, path: tp.path, lineno: tp.lineno, klass: tp.defined_class, method_name: tp.method_id }
36
+ node = SourceNode.new(parent, hash)
37
+ parent.add node
38
+ @stack.push node
39
+ end
40
+
41
+ @stack.pop if tp.event == :return && @stack.size > 1
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module RShade
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,44 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rshade/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rshade"
8
+ spec.version = RShade::VERSION
9
+ spec.authors = ["Ivan Lopatin"]
10
+ spec.email = ["gingray.dev@gmail.com"]
11
+
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"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+
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"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # 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
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_runtime_dependency 'colorize'
40
+
41
+ spec.add_development_dependency "bundler", "~> 1.16"
42
+ spec.add_development_dependency "rake", "~> 10.0"
43
+ spec.add_development_dependency "rspec", "~> 3.0"
44
+ end
Binary file
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rshade
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Lopatin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: https://github.com/gingray/rshade
70
+ email:
71
+ - gingray.dev@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/rshade.rb
87
+ - lib/rshade/filter.rb
88
+ - lib/rshade/helper.rb
89
+ - lib/rshade/rspec.rb
90
+ - lib/rshade/source_node.rb
91
+ - lib/rshade/trace.rb
92
+ - lib/rshade/version.rb
93
+ - rshade.gemspec
94
+ - shade.jpg
95
+ homepage: https://github.com/gingray/rshade
96
+ licenses:
97
+ - MIT
98
+ metadata:
99
+ allowed_push_host: https://rubygems.org
100
+ homepage_uri: https://github.com/gingray/rshade
101
+ source_code_uri: https://github.com/gingray/rshade
102
+ changelog_uri: https://github.com/gingray/rshade/CHANGELOG.md
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.7.8
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: https://github.com/gingray/rshade
123
+ test_files: []