hyper-trace 0.99.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c1b9434cfff5cca792bbe2339fca20449e7c69fce8fd01ec4d2319049275552a
4
+ data.tar.gz: 81be044684fe171674624b7f61551c5a1de74feb9b03463d0d83839259a66450
5
+ SHA512:
6
+ metadata.gz: b85b57a316236f09432e8c387465711f462b166bdddb503fe36d48ebf30bd0f441224eec4d8757ef57be96e688e736ddabab5fb78ced9ef2c3f01a785d25539a
7
+ data.tar.gz: f4a5688c1a0649e94afd89557e563a4879b4487b411950904b2311f36430fa488082663190e6deb0c3948f718b69877265f2a6fb675e6b687e7e3a37105ade80
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at mitch@catprint.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/DOCS.md ADDED
@@ -0,0 +1,145 @@
1
+ # HyperTrace
2
+
3
+ Method tracing and conditional break points for [Opal](http://opalrb.org/) and [Hyperloop](http://ruby-hyperloop.io) debug.
4
+
5
+ Typically you are going to use this in Capybara or Opal-RSpec examples that you are debugging.
6
+
7
+ HyperTrace adds a `hypertrace` method to all classes that you will use to switch on tracing and break points.
8
+
9
+ For example:
10
+
11
+ ```ruby
12
+ SomeClass.hypertrace instrument: :all
13
+ ```
14
+
15
+ Will instrument all methods in `SomeClass` and you will get a trace like this:
16
+
17
+ <img width="952" alt="screen shot 2016-10-22 at 11 08 56 pm" src="https://cloud.githubusercontent.com/assets/63146/19624133/48098fce-98b6-11e6-9198-cc5eae836ccf.png">
18
+
19
+ The trace log uses the javascript console grouping mechanism, so you can explore in detail the args, return values and state of the instance as each method executes.
20
+
21
+ instead of `:all` you can specify a single method, or an array of methods. Use the array notation if you happen to want to trace just the method `:all`.
22
+
23
+ #### Breakpoints
24
+
25
+ ```ruby
26
+ SomeClass.hypertrace break_on_enter: :foo
27
+ ```
28
+
29
+ Will break on entry to `SomeClass#foo` and `self` will be set the instance. The equivalent `break_on_exit` method will also store the result in a javascript variable called `RESULT`.
30
+
31
+ #### Conditional Breakpoints
32
+
33
+ ```ruby
34
+ SomeClass.hypertrace break_on_enter?: {foo: ->(arg1, arg2 ...) { ... }}
35
+ ```
36
+
37
+ The proc will be called before each call to `SomeClass#foo`, and any args passed to foo will be matched to the args, and the proc's instance will be set the foo's instance. If the proc returns a falsy value the breakpoint will be skipped.
38
+
39
+ #### Instrumenting Class methods
40
+
41
+ If the first argument is `:class` hypertrace will instrument the class methods.
42
+
43
+ ```ruby
44
+ SomeClass.hypertrace :class instrument: :some_class_method
45
+ ```
46
+
47
+ #### DSL
48
+
49
+ You can also use a simple DSL:
50
+
51
+ ```ruby
52
+ SomeClass.hypertrace do
53
+ instrument [:foo, :bar]
54
+ break_on_exit :baz
55
+ break_on_enter? :ralph do |p1, p2|
56
+ # executes with self set the instance, p1, p2 will be the
57
+ # first two args passed to ralph
58
+ p1 == p2 # break if p1 == p2
59
+ end
60
+ end
61
+ ```
62
+
63
+ #### Switching it off
64
+
65
+ ```ruby
66
+ SomeClass.hypertrace instrument: :none
67
+ ```
68
+
69
+ #### Inside of classes
70
+
71
+ Of course you can switch hypertrace on inside of your classes for quick debugging. Just remember that hypertrace applies
72
+ only to currently defined methods.
73
+
74
+ ```ruby
75
+ SomeClass
76
+ ...
77
+ hypertrace instrument: :all
78
+ end
79
+ ```
80
+
81
+ #### Works with Hyper-React (Reactrb)
82
+
83
+ If you hypertrace a React Component class you will get information on the component lifecycle, and the component state will include react state variables, and params (props) as well as normal instance variables.
84
+
85
+ ## Installation
86
+
87
+ Add this line to your application's Gemfile:
88
+
89
+ ```ruby
90
+ gem 'hyper-trace'
91
+ ```
92
+
93
+ And then execute:
94
+
95
+ $ bundle
96
+
97
+ Or install it yourself as:
98
+
99
+ $ gem install hyper-trace
100
+
101
+ Once installed add `require 'hyper-trace'` to your application or component manifest file. This gem works best if you are using Capybara or opal rspec, in which case you can reference the gem in the test application's manifest.
102
+
103
+
104
+ ## Custom Class Definitions
105
+
106
+ If class instance responds to `hypertrace_format_instance` then that method will be called to format the state information.
107
+
108
+ The method will be passed a hypertrace context object that will respond to the following methods:
109
+
110
+ + `format_instance(instance_vars = nil, &block)`
111
+ log the default instance header information. If instance_vars is nil then all instance vars will be printed. Otherwise instance_vars should be an array of the instance vars to display. The block will be executed to provide other details following the instance vars.
112
+ + `safe_i(object)`:
113
+ call inspect on an object will work even if the object is a native js object.
114
+ + `safe_s(object)`:
115
+ call to_s on an object safely
116
+ + `log(s)`
117
+ print a s to the log, nested at the current grouping level
118
+ + `group(header, collapsed: false, &block)`
119
+ create a new nesting group. If collapsed is true then the group will be initially closed. If block is present it will provide the contents of the group.
120
+
121
+ If the method `hypertrace_exclusions` is defined, it can return an array of methods names that will be not
122
+ be shown unless explicitly named.
123
+
124
+ For more details see the react_trace.rb module in this gem.
125
+
126
+ ## Development
127
+
128
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
129
+
130
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
131
+
132
+ ## Contributing
133
+
134
+ This is a very simple work in progress. Any and all help is requested. Things to do:
135
+
136
+ 2. Conditional tracing
137
+ 2. Add ability to specify `to_s` and `inspect` methods for use during tracing
138
+ 3. Add ability to specify `HyperTrace` delegator classes
139
+ 5. Add some tests
140
+
141
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hyper-trace. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
142
+
143
+ ## License
144
+
145
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gem 'hyperloop-config', path: '../hyperloop-config'
3
+ # Specify your gem's dependencies in hyper-trace.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hyper-trace (0.3.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.5.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.12)
16
+ hyper-trace!
17
+ rake (~> 10.0)
18
+
19
+ BUNDLED WITH
20
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 catmando
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.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ <div class="githubhyperloopheader">
2
+
3
+ <p align="center">
4
+
5
+ <a href="http://ruby-hyperloop.org/" alt="Hyperloop" title="Hyperloop">
6
+ <img width="350px" src="http://ruby-hyperloop.org/images/hyperloop-github-logo.png">
7
+ </a>
8
+
9
+ </p>
10
+
11
+ <h2 align="center">The Complete Isomorphic Ruby Framework</h2>
12
+
13
+ <br>
14
+
15
+ <a href="http://ruby-hyperloop.org/" alt="Hyperloop" title="Hyperloop">
16
+ <img src="http://ruby-hyperloop.org/images/githubhyperloopbadge.png">
17
+ </a>
18
+
19
+ <a href="https://gitter.im/ruby-hyperloop/chat" alt="Gitter chat" title="Gitter chat">
20
+ <img src="http://ruby-hyperloop.org/images/githubgitterbadge.png">
21
+ </a>
22
+
23
+ [![Gem Version](https://badge.fury.io/rb/hyper-trace.svg)](https://badge.fury.io/rb/hyper-trace)
24
+
25
+ <p align="center">
26
+ <img src="http://ruby-hyperloop.org/images/HyperTracer.png" width="100" alt="Hyper-trace">
27
+ </p>
28
+
29
+ </div>
30
+
31
+ ## Hyper-Trace GEM is part of Hyperloop GEMS family
32
+
33
+ Build interactive Web applications quickly. Hyperloop encourages rapid development with clean, pragmatic design. With developer productivity as our highest goal, Hyperloop takes care of much of the hassle of Web development, so you can focus on innovation and delivering end-user value.
34
+
35
+ One language. One model. One set of tests. The same business logic and domain models running on the clients and the server. Hyperloop is fully integrated with Rails and also gives you unfettered access to the complete universe of JavaScript libraries (including React) from within your Ruby code. Hyperloop lets you build beautiful interactive user interfaces in Ruby.
36
+
37
+ Everything has a place in our architecture. Components deliver interactive user experiences, Operations encapsulate business logic, Models magically synchronize data between clients and servers, Policies govern authorization and Stores hold local state.
38
+
39
+ **Hyper-Trace** brings a method tracing and conditional break points for [Opal](http://opalrb.org/) and [Hyperloop](http://ruby-hyperloop.org) debug.
40
+
41
+ Typically you are going to use this in Capybara or Opal-RSpec examples that you are debugging.
42
+
43
+ HyperTrace adds a `hypertrace` method to all classes that you will use to switch on tracing and break points.
44
+
45
+ ## Getting Started
46
+
47
+ 1. Update your Gemfile:
48
+
49
+ ```ruby
50
+ #Gemfile
51
+
52
+ gem 'hyper-trace'
53
+ ```
54
+
55
+ 2. At the command prompt, update your bundle :
56
+
57
+ $ bundle update
58
+
59
+ 3. Run the gem install generator:
60
+
61
+ $ gem install hyper-trace
62
+
63
+ 4. Add `require 'hyper-trace'` to your application or component manifest file.
64
+
65
+ 5. Follow the Hyper-trace documentation:
66
+
67
+ * [Hyper-trace documentation](http://ruby-hyperloop.org/tools/hypertrace/)
68
+ * [Hyperloop Guides](http://ruby-hyperloop.org/docs/architecture)
69
+ * [Hyperloop Tutorial](http://ruby-hyperloop.org/tutorials)
70
+
71
+ ## Community
72
+
73
+ #### Getting Help
74
+ Please **do not post** usage questions to GitHub Issues. For these types of questions use our [Gitter chatroom](https://gitter.im/ruby-hyperloop/chat) or [StackOverflow](http://stackoverflow.com/questions/tagged/hyperloop).
75
+
76
+ #### Submitting Bugs and Enhancements
77
+ [GitHub Issues](https://github.com/ruby-hyperloop/hyperloop/issues) is for suggesting enhancements and reporting bugs. Before submiting a bug make sure you do the following:
78
+ * Check out our [contributing guide](https://github.com/ruby-hyperloop/hyperloop/blob/master/CONTRIBUTING.md) for info on our release cycle.
79
+
80
+ ## License
81
+
82
+ Hyperloop is released under the [MIT License](http://www.opensource.org/licenses/MIT).
83
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ task :default do
3
+ end
4
+
5
+ namespace :spec do
6
+ task :prepare do
7
+ end
8
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hyper/trace"
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
data/bin/setup ADDED
@@ -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,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hyper_trace/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hyper-trace"
8
+ spec.version = HyperTrace::VERSION
9
+ spec.authors = ["catmando"]
10
+ spec.email = ["mitch@catprint.com"]
11
+
12
+ spec.summary = %q{Method tracing and conditional breakpoints for Opal Ruby}
13
+ spec.homepage = "https://github.com/reactrb/hyper-trace"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'hyperloop-config', HyperTrace::VERSION
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency 'chromedriver-helper'
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
@@ -0,0 +1,8 @@
1
+ Hyperloop.import 'hyper-trace'
2
+ if RUBY_ENGINE=='opal'
3
+ require 'hyper_trace/hyper_trace.rb'
4
+ require 'hyper_trace/react_trace.rb'
5
+ else
6
+ require 'opal'
7
+ Opal.append_path File.expand_path('../', __FILE__).untaint
8
+ end
@@ -0,0 +1,354 @@
1
+ class Class
2
+ def hyper_trace(*args, &block)
3
+ return unless React::IsomorphicHelpers.on_opal_client?
4
+ HyperTrace.hyper_trace(self, *args, &block)
5
+ end
6
+ alias hypertrace hyper_trace
7
+ end
8
+
9
+ class Method
10
+ def parameters
11
+ /.*function[^(]*\(([^)]*)\)/
12
+ .match(`#{@method}.toString()`)[1]
13
+ .split(',')
14
+ .collect { |param| [:req, param.strip.to_sym] }
15
+ end
16
+ end
17
+
18
+ module HyperTrace
19
+
20
+ class Config
21
+ def initialize(klass, instrument_class, opts, &block)
22
+ @klass = klass
23
+ @opts = {}
24
+ @instrument_class = instrument_class
25
+ [:break_on_enter?, :break_on_entry?, :break_on_exit?, :break_on_enter, :break_on_entry, :break_on_exit, :instrument].each do |method|
26
+ send(method, opts[method]) if opts[method]
27
+ end unless opts[:instrument] == :none
28
+ instance_eval(&block) if block
29
+ end
30
+ def instrument_class?
31
+ @instrument_class
32
+ end
33
+ attr_reader :klass
34
+ def instrument(opt)
35
+ return if @opts[:instrument] == :all
36
+ if opt == :all
37
+ @opts[:instrument] = :all
38
+ else
39
+ @opts[:instrument] = [*opt, *@opts[:instrument]]
40
+ end
41
+ end
42
+ def break_on_exit(methods)
43
+ [*methods].each { |method| break_on_exit?(method) { true } }
44
+ end
45
+ def break_on_enter(methods)
46
+ [*methods].each { |method| break_on_enter?(method) { true } }
47
+ end
48
+ alias break_on_entry break_on_enter
49
+ def break_on_exit?(method, &block)
50
+ @opts[:break_on_exit?] ||= {}
51
+ @opts[:break_on_exit?][method] = block
52
+ instrument(method)
53
+ end
54
+ def break_on_enter?(method, &block)
55
+ @opts[:break_on_enter?] ||= {}
56
+ @opts[:break_on_enter?][method] = block
57
+ instrument(method)
58
+ end
59
+ alias break_on_entry? break_on_enter
60
+ def [](opt)
61
+ @opts[opt]
62
+ end
63
+ def hypertrace_class_exclusions
64
+ if klass.respond_to? :hypertrace_class_exclusions
65
+ klass.hypertrace_class_exclusions
66
+ else
67
+ []
68
+ end
69
+ end
70
+ def hypertrace_exclusions
71
+ if klass.respond_to? :hypertrace_exclusions
72
+ klass.hypertrace_exclusions
73
+ else
74
+ []
75
+ end
76
+ end
77
+ end
78
+
79
+
80
+ class << self
81
+ def hyper_trace(klass, *args, &block)
82
+ if args.count == 0
83
+ opts = { instrument: :all }
84
+ instrument_class = false
85
+ elsif args.first == :class
86
+ opts = args[1] || {}
87
+ instrument_class = true
88
+ else
89
+ opts = args.last || {}
90
+ instrument_class = false
91
+ end
92
+ begin
93
+ opts.is_a? Hash
94
+ rescue Exception
95
+ opts = Hash.new(opts)
96
+ end
97
+ config = Config.new(klass, instrument_class, opts, &block)
98
+ if config[:exclude]
99
+ exclusions[:instrumentation][klass] << opts[:exclude]
100
+ else
101
+ instrumentation_off(config)
102
+ selected_methods = if config[:instrument] == :all
103
+ all_methods(config)
104
+ else
105
+ Set.new config[:instrument]
106
+ end
107
+ selected_methods.each { |method| instrument_method(method, config) }
108
+ end
109
+ end
110
+
111
+ def exclusions
112
+ @exclusions ||= Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = Set.new } }
113
+ end
114
+
115
+ def instrumentation_off(config)
116
+ if config.instrument_class?
117
+ config.klass.methods.grep(/^__hyper_trace_pre_.+$/).each do |method|
118
+ config.klass.class_eval do
119
+ class << self
120
+ alias_method method.gsub(/^__hyper_trace_pre_/, ''), method
121
+ end
122
+ end
123
+ end
124
+ else
125
+ config.klass.instance_methods.grep(/^__hyper_trace_pre_.+$/).each do |method|
126
+ config.klass.class_eval { alias_method method.gsub(/^__hyper_trace_pre_/, ''), method }
127
+ end
128
+ end
129
+ end
130
+
131
+ def all_methods(config)
132
+ if config.instrument_class?
133
+ Set.new(config.klass.methods.grep(/^(?!__hyper_trace_)/)) -
134
+ Set.new(Class.methods + Object.methods) -
135
+ config.hypertrace_class_exclusions -
136
+ [:hypertrace_format_instance]
137
+ else
138
+ Set.new(config.klass.instance_methods.grep(/^(?!__hyper_trace_)/)) -
139
+ Set.new(Class.methods + Object.methods) -
140
+ config.hypertrace_exclusions -
141
+ [:hypertrace_format_instance]
142
+ end
143
+ end
144
+
145
+ def instrument_method(method, config)
146
+ if config.instrument_class?
147
+ config.klass.class_eval do
148
+ class << self
149
+ alias_method "__hyper_trace_pre_#{method}", method unless method_defined? "__pre_hyper_trace_#{method}"
150
+ end
151
+ end
152
+ add_hyper_trace_method(method, config)
153
+ else
154
+ unless config.klass.method_defined? "__pre_hyper_trace_#{method}"
155
+ config.klass.class_eval do
156
+ alias_method "__hyper_trace_pre_#{method}", method
157
+ end
158
+ end
159
+ end
160
+ add_hyper_trace_method(method, config)
161
+ end
162
+
163
+ def formatting?
164
+ @formatting
165
+ end
166
+
167
+ def safe_s(obj)
168
+ obj.to_s
169
+ rescue Exception
170
+ "native object"
171
+ end
172
+
173
+ def safe_i(obj)
174
+ "#{obj.inspect}"
175
+ rescue Exception
176
+ begin
177
+ "native: #{`JSON.stringify(obj)`}"
178
+ rescue Exception
179
+ safe_s(obj)
180
+ end
181
+ end
182
+
183
+ def show_js_object(obj)
184
+ return true
185
+ safe(obj) != obj
186
+ rescue Exception
187
+ nil
188
+ end
189
+
190
+ def instance_tag(instance, prefix = ' - ')
191
+ if instance.instance_variables.any?
192
+ "#{prefix}#<#{instance.class}:0x#{instance.object_id.to_s(16)}>"
193
+ end
194
+ end
195
+
196
+ def format_head(instance, name, args, &block)
197
+ @formatting = true
198
+ method = instance.method("__hyper_trace_pre_#{name}")
199
+ if args.any?
200
+ group(" #{name}(...)#{instance_tag(instance)}") do
201
+ params = method.parameters
202
+ group("args:", collapsed: true) do
203
+ params.each_with_index do |param_spec, i|
204
+ arg_name = param_spec[1]
205
+ if arg_name == '$a_rest'
206
+ arg_name = '*'
207
+ arg = args[i..-1]
208
+ else
209
+ arg = args[i]
210
+ end
211
+ if safe_i(arg).length > 30 || show_js_object(arg)
212
+ group "#{arg_name}: #{safe_s(arg)}"[0..29], collapsed: true do
213
+ puts safe_i(arg)
214
+ log arg if show_js_object(arg)
215
+ end
216
+ else
217
+ group "#{arg_name}: #{safe_i(arg)}"
218
+ end
219
+ end
220
+ end
221
+ yield
222
+ end
223
+ else
224
+ group " #{name}()#{instance_tag(instance)}", &block
225
+ end
226
+ ensure
227
+ @formatting = false
228
+ end
229
+
230
+ def log(s)
231
+ `console.log(#{s})`
232
+ end
233
+
234
+ def group(s, collapsed: false, &block)
235
+ if collapsed
236
+ `console.groupCollapsed(#{s})`
237
+ else
238
+ `console.group(#{s})`
239
+ end
240
+ yield if block
241
+ ensure
242
+ `console.groupEnd()`
243
+ end
244
+
245
+ def format_instance_internal(instance)
246
+ if instance.respond_to? :hypertrace_format_instance
247
+ instance.hypertrace_format_instance(self)
248
+ else
249
+ format_instance(instance, instance.instance_variables)
250
+ end
251
+ end
252
+
253
+ def format_instance(instance, filter = nil, &block)
254
+ filtered_instance_variables = if filter
255
+ filter
256
+ else
257
+ instance.instance_variables
258
+ end
259
+ return if filtered_instance_variables.empty? && block.nil?
260
+ group "self:#{instance_tag(instance,' ')}", collapsed: true do
261
+ puts safe_i(instance) unless safe_i(instance).length < 40
262
+ filtered_instance_variables.each do |iv|
263
+ val = safe_i(instance.instance_variable_get(iv))
264
+ group "#{iv}: #{val[0..10]}", collapsed: true do
265
+ puts val
266
+ log instance.instance_variable_get(iv)
267
+ end
268
+ end
269
+ yield if block
270
+ end
271
+ end
272
+
273
+ def format_result(result)
274
+ if safe_i(result).length > 40 || show_js_object(result)
275
+ group "returns: #{safe_s(result)}"[0..40], collapsed: true do
276
+ puts safe_i(result)
277
+ log result if show_js_object(result)
278
+ end
279
+ else
280
+ group "returns: #{safe_i(result)}"
281
+ end
282
+ end
283
+
284
+ def format_exception(result)
285
+ @formatting = true
286
+ if safe_i(result).length > 40
287
+ group "raised: #{safe_s(result)}"[0..40], collapsed: true do
288
+ puts safe_i(result)
289
+ end
290
+ else
291
+ group "raised: #{safe_i(result)}"
292
+ end
293
+ ensure
294
+ @formatting = false
295
+ end
296
+
297
+ def should_break?(location, config, name, args, instance, result)
298
+ breaker = config["break_on_#{location}?"]
299
+ breaker &&= breaker[name] || breaker[:all]
300
+ return unless breaker
301
+ args = [result, *args] if location == 'exit'
302
+ instance.instance_exec(*args, &breaker)
303
+ end
304
+
305
+ def breakpoint(location, config, name, args, instance, result = nil)
306
+ if should_break? location, config, name, args, instance, result
307
+ method = instance.method("__hyper_trace_pre_#{name}")
308
+ fn_def = ['RESULT']
309
+ fn_def += method.parameters.collect { |p| p[1] }
310
+ fn_def += ["//break on #{location} of #{name}\nvar self = this;\ndebugger;\n;"]
311
+ puts "break on #{location} of #{name}"
312
+ fn = `Function.apply(#{self}, #{fn_def}).bind(#{instance})`
313
+ fn.call(result, *args)
314
+ end
315
+ end
316
+
317
+ def call_original(instance, method, *args, &block)
318
+ @formatting = false
319
+ instance.send "__hyper_trace_pre_#{method}", *args, &block
320
+ ensure
321
+ @formatting = true
322
+ end
323
+
324
+
325
+ def add_hyper_trace_method(method, config)
326
+ def_method = config.instrument_class? ? :define_singleton_method : :define_method
327
+ config.klass.send(def_method, method) do |*args, &block|
328
+ block_string = ' { ... }' if block
329
+ if HyperTrace.formatting?
330
+ begin
331
+ send "__hyper_trace_pre_#{method}", *args, &block
332
+ rescue Exception
333
+ "???"
334
+ end
335
+ else
336
+ begin
337
+ HyperTrace.format_head(self, method, args) do
338
+ HyperTrace.format_instance_internal(self)
339
+ HyperTrace.breakpoint(:enter, config, method, args, self)
340
+ result = HyperTrace.call_original self, method, *args, &block
341
+ HyperTrace.format_result(result)
342
+ HyperTrace.breakpoint(:exit, config, method, args, self, result)
343
+ result
344
+ end
345
+ rescue Exception => e
346
+ HyperTrace.format_exception(e)
347
+ debugger unless HyperTrace.exclusions[self.class][:rescue].include? :method
348
+ raise e
349
+ end
350
+ end
351
+ end
352
+ end
353
+ end
354
+ end
@@ -0,0 +1,47 @@
1
+
2
+ module React
3
+ module Component
4
+ module ClassMethods
5
+ def hypertrace_exclusions
6
+ @@hypertrace_exclusions ||=
7
+ Tags::HTML_TAGS +
8
+ Tags::HTML_TAGS.collect { |t| t.upcase } +
9
+ [
10
+ :_render_wrapper, :params, :find_component, :lookup_const,
11
+ :update_react_js_state, :props_changed?,
12
+ :update_react_js_state2, :set_state, :original_component_did_mount,
13
+ :props, :reactive_record_link_to_enclosing_while_loading_container,
14
+ :reactive_record_link_set_while_loading_container_class,
15
+ :dom_node, :state, :run_callback, :initial_state, :set_state!,
16
+ :set_or_replace_state_or_prop, :original_component_did_update
17
+ ]
18
+ end
19
+ end
20
+ module DslInstanceMethods
21
+ def hypertrace_format_instance(h)
22
+ filtered_vars =
23
+ instance_variables -
24
+ ['@native', '@props_wrapper', '@state_wrapper', '@waiting_on_resources']
25
+ h.format_instance(self, filtered_vars) do
26
+ @props_wrapper.props.each do |param, value|
27
+ val = h.safe_i value
28
+ h.group("params.#{param}: #{val[0..10]}", collapsed: true) do
29
+ puts val
30
+ h.log value
31
+ end
32
+ end if @props_wrapper
33
+ hash = Hash.new(`#{@native}.state`)
34
+ updated_at = hash.delete('***_state_updated_at-***')
35
+ h.group("state last updated at: #{Time.at(updated_at)}") if updated_at
36
+ hash.each do |state, value|
37
+ val = h.safe_i(value)
38
+ h.group("state.#{state}: #{val[0..10]}", collapsed: true) do
39
+ puts val
40
+ h.log value
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module HyperTrace
2
+ VERSION = "0.99.0"
3
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hyper-trace
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.99.0
5
+ platform: ruby
6
+ authors:
7
+ - catmando
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hyperloop-config
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.99.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.99.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.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: chromedriver-helper
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description:
70
+ email:
71
+ - mitch@catprint.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - CODE_OF_CONDUCT.md
78
+ - DOCS.md
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - hyper-trace.gemspec
87
+ - lib/hyper-trace.rb
88
+ - lib/hyper_trace/hyper_trace.rb
89
+ - lib/hyper_trace/react_trace.rb
90
+ - lib/hyper_trace/version.rb
91
+ homepage: https://github.com/reactrb/hyper-trace
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.7.7
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Method tracing and conditional breakpoints for Opal Ruby
115
+ test_files: []