web-console 2.3.0 → 4.2.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.
Files changed (46) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.markdown +133 -1
  3. data/MIT-LICENSE +1 -1
  4. data/README.markdown +48 -86
  5. data/Rakefile +14 -12
  6. data/lib/web-console.rb +3 -1
  7. data/lib/web_console/context.rb +45 -0
  8. data/lib/web_console/errors.rb +2 -0
  9. data/lib/web_console/evaluator.rb +14 -5
  10. data/lib/web_console/exception_mapper.rb +56 -0
  11. data/lib/web_console/extensions.rb +28 -17
  12. data/lib/web_console/injector.rb +32 -0
  13. data/lib/web_console/interceptor.rb +18 -0
  14. data/lib/web_console/locales/en.yml +1 -1
  15. data/lib/web_console/middleware.rb +31 -31
  16. data/lib/web_console/permissions.rb +42 -0
  17. data/lib/web_console/railtie.rb +38 -24
  18. data/lib/web_console/request.rb +8 -20
  19. data/lib/web_console/session.rb +32 -18
  20. data/lib/web_console/source_location.rb +15 -0
  21. data/lib/web_console/tasks/extensions.rake +15 -13
  22. data/lib/web_console/tasks/templates.rake +56 -0
  23. data/lib/web_console/template.rb +4 -3
  24. data/lib/web_console/templates/console.js.erb +497 -37
  25. data/lib/web_console/templates/error_page.js.erb +7 -8
  26. data/lib/web_console/templates/index.html.erb +4 -0
  27. data/lib/web_console/templates/layouts/inlined_string.erb +1 -1
  28. data/lib/web_console/templates/layouts/javascript.erb +1 -1
  29. data/lib/web_console/templates/regular_page.js.erb +24 -0
  30. data/lib/web_console/templates/style.css.erb +182 -27
  31. data/lib/web_console/testing/erb_precompiler.rb +5 -3
  32. data/lib/web_console/testing/fake_middleware.rb +7 -10
  33. data/lib/web_console/testing/helper.rb +3 -1
  34. data/lib/web_console/version.rb +3 -1
  35. data/lib/web_console/view.rb +24 -3
  36. data/lib/web_console/whiny_request.rb +8 -6
  37. data/lib/web_console.rb +28 -20
  38. metadata +28 -63
  39. data/lib/web_console/helper.rb +0 -22
  40. data/lib/web_console/integration/cruby.rb +0 -40
  41. data/lib/web_console/integration/jruby.rb +0 -111
  42. data/lib/web_console/integration/rubinius.rb +0 -67
  43. data/lib/web_console/integration.rb +0 -8
  44. data/lib/web_console/response.rb +0 -23
  45. data/lib/web_console/tasks/test_templates.rake +0 -50
  46. data/lib/web_console/whitelist.rb +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 02d40821ae813ac4e5893b4c853725833017cb46
4
- data.tar.gz: 56b2826919677b8a93e6ecedce69a176949d15ee
2
+ SHA256:
3
+ metadata.gz: a491428cda19f89cf20ad5ef83558e948feecb7acb7f46b453c5644ad419131b
4
+ data.tar.gz: 3e3d2902466fc03684b00591b294df2c19af06db31e43f58f1f9e8de14cb731f
5
5
  SHA512:
6
- metadata.gz: 6c6a07f241b5bfad39c7a588ac92bccc8f0786db1b807d3ab94b4ec13464d7d8514493634c88247a868e78e43169094d216da6f01c3559be45af39854a76a0a0
7
- data.tar.gz: 4b656f08efb441715996f541f94806d9f6249171502fded529041c5fc5cead0a73ce4f155fe246f0c4a36c4a0b54f9bdd65fb3091ed5e9b9bfa86b9d95f3a552
6
+ metadata.gz: d949e602f1056bda92b2e7e13e030a78bd856befeb52ccd89c57c27a5341bab30830e27969f3fd9bf8e3d5e4467de381cb788cd9d5809ad6f5d662b2a00b3993
7
+ data.tar.gz: a17229c83c77f2fdc2b06ca4d25674391e9318490da932de015d0d8ebc59bf652ccb010577eea9d95c357fcd703ba6b5fb8f2afc8343ad79306e80834f52d77d
data/CHANGELOG.markdown CHANGED
@@ -2,14 +2,127 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 4.2.0
6
+
7
+ * [#308](https://github.com/rails/web-console/pull/308) Fix web-console inline templates rendering ([@voxik])
8
+ * [#306](https://github.com/rails/web-console/pull/306) Support Ruby 3.0 and above ([@ruanwood])
9
+
10
+ ## 4.1.0
11
+
12
+ * [#304](https://github.com/rails/web-console/pull/304) Add support for Rails 6.1 ([@stephannv])
13
+ * [#298](https://github.com/rails/web-console/pull/298) Prevent deprecation warnings by removing template formats ([@mikelkew])
14
+ * [#297](https://github.com/rails/web-console/pull/297) Use MutationObserver instead of Mutation Events ([@mikelkew])
15
+ * [#296](https://github.com/rails/web-console/pull/296) Add CSP nonce to injected scripts and styles ([@mikelkew])
16
+
17
+ ## 4.0.4
18
+
19
+ * [fb483743](https://github.com/rails/web-console/commit/fb483743a6a2a4168cdc0b2e03f48fc393991b73) Fix a crash on webrick with Rack 2.2.3 ([@gsamokovarov])
20
+
21
+ ## 4.0.3
22
+
23
+ * [#291](https://github.com/rails/web-console/pull/291) Deprecate config.web_console.whitelisted_ips ([@JuanitoFatas])
24
+ * [#290](https://github.com/rails/web-console/pull/290) Fix Content-Length for rack >= 2.1.0 ([@p8])
25
+
26
+ ## 4.0.2
27
+
28
+ * [#285](https://github.com/rails/web-console/pull/285) Increase timeout on paste ([@celvro])
29
+
30
+ ## 4.0.1
31
+
32
+ * [#279](https://github.com/rails/web-console/pull/279) Fix initial config.web_console.permissions value ([@patorash])
33
+
34
+ ## 4.0.0
35
+
36
+ * [61ce65b5](https://github.com/rails/web-console/commit/61ce65b599f56809de1bd8da6590a80acbd92017) Move to config.web_console.permissions ([@gsamokovarov])
37
+ * [96127ac1](https://github.com/rails/web-console/commit/96127aac143e1e653fffdc4bb65e1ce0b5ff342d) Introduce Binding#console as an alternative interface ([@gsamokovarov])
38
+ * [d4591ca5](https://github.com/rails/web-console/commit/d4591ca5396ed15a08818f3da11134852a485b27) Introduce Rails 6 support ([@gsamokovarov])
39
+ * [f97d8a88](https://github.com/rails/web-console/commit/f97d8a889a38366485e5c5e8985995c19bf61d13) Introduce Ruby 2.6 support ([@gsamokovarov])
40
+ * [d6deacd9](https://github.com/rails/web-console/commit/d6deacd9d5fcaabf3e3051d6985b53f924f86956) Drop Rails 5 support ([@gsamokovarov])
41
+ * [90fda878](https://github.com/rails/web-console/commit/90fda8789d402f05647c18f8cdf8e5c3d01692dd) Drop Ruby 2.4 support ([@gsamokovarov])
42
+ * [#265](https://github.com/rails/web-console/pull/265) Add support for nested exceptions ([@yuki24])
43
+
44
+ ## 3.7.0
45
+
46
+ * [#263](https://github.com/rails/web-console/pull/263) Show binding changes ([@causztic])
47
+ * [#258](https://github.com/rails/web-console/pull/258) Support Ctrl-A, Ctrl-W and Ctrl-U ([@gsamokovarov])
48
+ * [#257](https://github.com/rails/web-console/pull/257) Always try to keep the console underneath the website content ([@gsamokovarov])
49
+
50
+ ## 3.6.2
51
+
52
+ * [#255](https://github.com/rails/web-console/pull/255) Fix the truncated HTML body, because of wrong Content-Length header ([@timomeh])
53
+
54
+ ## 3.6.1
55
+
56
+ * [#252](https://github.com/rails/web-console/pull/252) Fix improper injection in Rack bodies like ActionDispatch::Response::RackBody ([@gsamokovarov])
57
+
58
+ ## 3.6.0
59
+
60
+ * [#254](https://github.com/rails/web-console/pull/254) Rescue ActionDispatch::RemoteIp::IpSpoofAttackError ([@wjordan])
61
+ * [#250](https://github.com/rails/web-console/pull/250) Close original body to comply with Rack SPEC ([@wagenet])
62
+ * [#249](https://github.com/rails/web-console/pull/249) Update for frozen-string-literal friendliness ([@pat])
63
+ * [#248](https://github.com/rails/web-console/pull/248) Fix copy on Safari ([@ybart])
64
+ * [#246](https://github.com/rails/web-console/pull/246) International keyboard special character input fixes ([@fl0l0u])
65
+ * [#244](https://github.com/rails/web-console/pull/244) Let WebConsole.logger respect Rails.logger ([@gsamokovarov])
66
+
67
+ ## 3.5.1
68
+
69
+ * [#239](https://github.com/rails/web-console/pull/239) Fix the ActionDispatch::DebugExceptions integration ([@gsamokovarov])
70
+
71
+ ## 3.5.0
72
+
73
+ * [#237](https://github.com/rails/web-console/pull/237) Bindex integration for JRuby 9k support ([@gsamokovarov])
74
+ * [#236](https://github.com/rails/web-console/pull/236) Remove unused Active Support lazy load hook ([@betesh])
75
+ * [#230](https://github.com/rails/web-console/pull/230) Handle invalid remote addresses ([@akirakoyasu])
76
+
77
+ ## 3.4.0
78
+
79
+ * [#205](https://github.com/rails/web-console/pull/205) Introduce autocompletion ([@sh19910711])
80
+
81
+ ## 3.3.1
82
+
83
+ Drop support for Rails `4.2.0`.
84
+
85
+ ## 3.3.0
86
+
87
+ * [#203](https://github.com/rails/web-console/pull/203) Map bindings to traces based on the trace __FILE__ and __LINE__ ([@gsamokovarov])
88
+
89
+ ## 3.2.1
90
+
91
+ * [#202](https://github.com/rails/web-console/pull/202) Use first binding when there is no application binding ([@sh19910711])
92
+
93
+ ## 3.2.0
94
+
95
+ * [#198](https://github.com/rails/web-console/pull/198) Pick the first application trace binding on errors ([@sh19910711])
96
+ * [#189](https://github.com/rails/web-console/pull/189) Silence ActionView rendering information ([@gsamokovarov])
97
+
98
+ ## 3.1.1
99
+
100
+ * [#185](https://github.com/rails/web-console/pull/185) Fix `rails console` startup ([@gsamokovarov])
101
+
102
+ ## 3.1.0
103
+
104
+ * [#182](https://github.com/rails/web-console/pull/182) Let `#console` live in `Kernel` ([@schneems])
105
+ * [#181](https://github.com/rails/web-console/pull/181) Log internal Web Console errors ([@gsamokovarov])
106
+ * [#180](https://github.com/rails/web-console/pull/180) Autoload Web Console constants for faster Rails boot time ([@herminiotorres])
107
+
108
+ ## 3.0.0
109
+
110
+ * [#173](https://github.com/rails/web-console/pull/173) Revert "Change config.development_only default until 4.2.4 is released" ([@gsamokovarov])
111
+ * [#171](https://github.com/rails/web-console/pull/171) Fixed blocked IP logging ([@gsamokovarov])
112
+ * [#162](https://github.com/rails/web-console/pull/162) Render the console inside the body tag ([@gsamokovarov])
113
+ * [#165](https://github.com/rails/web-console/pull/165) Revamped integrations for CRuby and Rubinius ([@gsamokovarov])
114
+
5
115
  ## 2.3.0
6
116
 
117
+ This is mainly a Rails 5 compatibility release. If you have the chance, please
118
+ go to 3.1.0 instead.
119
+
7
120
  * [#181](https://github.com/rails/web-console/pull/181) Log internal Web Console errors ([@schneems])
8
121
  * [#150](https://github.com/rails/web-console/pull/150) Revert #150. ([@gsamokovarov])
9
122
 
10
123
  ## 2.2.1
11
124
 
12
- * [#150](https://github.com/rails/web-console/pull/150) Change config.development_only default until 4.2.4 is released. ([@gsamokovarov])
125
+ * [#150](https://github.com/rails/web-console/pull/150) Change config.development_only default until 4.2.4 is released ([@gsamokovarov])
13
126
 
14
127
  ## 2.2.0
15
128
 
@@ -44,6 +157,8 @@
44
157
  * [#84](https://github.com/rails/web-console/pull/84) Allow Rails 5 as dependency in gemspec ([@jonatack])
45
158
  * [#69](https://github.com/rails/web-console/pull/69) Introduce middleware for request dispatch and console rendering ([@gsamokovarov])
46
159
 
160
+ [@stephannv]: https://github.com/stephannv
161
+ [@mikelkew]: https://github.com/mikelkew
47
162
  [@jonatack]: https://github.com/jonatack
48
163
  [@ryandao]: https://github.com/ryandao
49
164
  [@jeffnv]: https://github.com/jeffnv
@@ -53,4 +168,21 @@
53
168
  [@parterburn]: https://github.com/parterburn
54
169
  [@sh19910711]: https://github.com/sh19910711
55
170
  [@frenesim]: https://github.com/frenesim
171
+ [@herminiotorres]: https://github.com/herminiotorres
56
172
  [@schneems]: https://github.com/schneems
173
+ [@betesh]: https://github.com/betesh
174
+ [@akirakoyasu]: https://github.com/akirakoyasu
175
+ [@wagenet]: https://github.com/wagenet
176
+ [@wjordan]: https://github.com/wjordan
177
+ [@pat]: https://github.com/pat
178
+ [@ybart]: https://github.com/ybart
179
+ [@fl0l0u]: https://github.com/fl0l0u
180
+ [@timomeh]: https://github.com/timomeh
181
+ [@causztic]: https://github.com/causztic
182
+ [@yuki24]: https://github.com/yuki24
183
+ [@patorash]: https://github.com/patorash
184
+ [@celvro]: https://github.com/celvro
185
+ [@JuanitoFatas]: https://github.com/JuanitoFatas
186
+ [@p8]: https://github.com/p8
187
+ [@voxik]: https://github.com/voxik
188
+ [@ryanwood]: https://github.com/ryanwood
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2014 Charlie Somerville, Genadi Samokovarov, Guillermo Iguaran and Ryan Dao
1
+ Copyright 2014-2016 Hailey Somerville, Genadi Samokovarov, Guillermo Iguaran and Ryan Dao
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.markdown CHANGED
@@ -1,10 +1,8 @@
1
1
  <p align=right>
2
- Documentation for:
3
- <a href=https://github.com/rails/web-console/tree/v2.0.0>v2.0.0</a>
4
- <a href=https://github.com/rails/web-console/tree/v2.1.0>v2.1.0</a>
5
- <a href=https://github.com/rails/web-console/tree/v2.1.1>v2.1.1</a>
6
- <a href=https://github.com/rails/web-console/tree/v2.1.2>v2.1.2</a>
7
- <a href=https://github.com/rails/web-console/tree/v2.1.3>v2.1.3</a>
2
+ <strong>Current version: 4.1.0</strong> | Documentation for:
3
+ <a href=https://github.com/rails/web-console/tree/v1.0.4>v1.0.4</a>
4
+ <a href=https://github.com/rails/web-console/tree/v2.2.1>v2.2.1</a>
5
+ <a href=https://github.com/rails/web-console/tree/v3.7.0>v3.7.0</a>
8
6
  </p>
9
7
 
10
8
  # Web Console [![Build Status](https://travis-ci.org/rails/web-console.svg?branch=master)](https://travis-ci.org/rails/web-console)
@@ -12,10 +10,6 @@
12
10
  _Web Console_ is a debugging tool for your Ruby on Rails applications.
13
11
 
14
12
  - [Installation](#installation)
15
- - [Runtime](#runtime)
16
- - [CRuby](#cruby)
17
- - [JRuby](#jruby)
18
- - [Rubinius](#rubinius)
19
13
  - [Configuration](#configuration)
20
14
  - [Usage](#usage)
21
15
  - [FAQ](#faq)
@@ -23,59 +17,19 @@ _Web Console_ is a debugging tool for your Ruby on Rails applications.
23
17
 
24
18
  ## Installation
25
19
 
26
- _Web Console_ is meant to work as a Rails plugin. To install it in your current
27
- application, add the following to your `Gemfile`.
20
+ Add the following to your `Gemfile`:
28
21
 
29
22
  ```ruby
30
23
  group :development do
31
- gem 'web-console', '~> 2.0'
24
+ gem 'web-console'
32
25
  end
33
26
  ```
34
27
 
35
- After you save the `Gemfile` changes, make sure to run `bundle install` and
36
- restart your server for the _Web Console_ to kick in.
37
-
38
- ## Runtime
39
-
40
- _Web Console_ uses [John Mair]'s [binding_of_caller] to spawn a console in a
41
- specific binding. This comes at the price of limited Ruby runtime support.
42
-
43
- ### CRuby
44
-
45
- CRuby 1.9.2 and below is **not** supported.
46
-
47
- ### JRuby
48
-
49
- JRuby needs to run in interpreted mode. You can enable it by:
50
-
51
- ```bash
52
- export JRUBY_OPTS=-J-Djruby.compile.mode=OFF
53
-
54
- # If you run JRuby 1.7.12 and above, you can use:
55
- export JRUBY_OPTS=--dev
56
- ```
57
-
58
- An unstable version of [binding_of_caller] is needed as the latest stable one
59
- won't compile on _JRuby_. To install it, put the following in your application
60
- `Gemfile`:
61
-
62
- ```ruby
63
- group :development do
64
- gem 'binding_of_caller', '0.7.3.pre1'
65
- end
66
- ```
67
-
68
- Only _JRuby_ 1.7, is supported (no JRuby 9K support at the moment).
69
-
70
- ### Rubinius
71
-
72
- Internal errors like `ZeroDevisionError` aren't caught.
73
-
74
28
  ## Usage
75
29
 
76
30
  The web console allows you to create an interactive Ruby session in your
77
- browser. Those sessions are launched automatically in case on an error, but
78
- they can also be launched manually in in any page.
31
+ browser. Those sessions are launched automatically in case of an error and can
32
+ also be launched manually in any page.
79
33
 
80
34
  For example, calling `console` in a view will display a console in the current
81
35
  page in the context of the view binding.
@@ -96,35 +50,37 @@ class PostsController < ApplicationController
96
50
  end
97
51
  ```
98
52
 
99
- Only one `console` invocation is allowed per request. If you happen to have
100
- multiple ones, a `WebConsole::DoubleRenderError` is raised.
53
+ The method is defined in `Kernel` and you can invoke it any application code.
54
+
55
+ Only one `console` invocation per request is allowed. If you happen to
56
+ have multiple ones, `WebConsole::DoubleRenderError` will be raised.
101
57
 
102
58
  ## Configuration
103
59
 
104
- _Web Console_ allows you to execute arbitrary code on the server, so you
105
- should be very careful, who you give access to.
60
+ _Web Console_ allows you to execute arbitrary code on the server. Therefore, be
61
+ very careful who you give access to.
106
62
 
107
- ### config.web_console.whitelisted_ips
63
+ ### config.web_console.permissions
108
64
 
109
65
  By default, only requests coming from IPv4 and IPv6 localhosts are allowed.
110
66
 
111
- `config.web_console.whitelisted_ips` lets you control which IP's have access to
67
+ `config.web_console.permissions` lets you control which IP's have access to
112
68
  the console.
113
69
 
114
- You can whitelist single IP's or whole networks. Say you want to share your
115
- console with `192.168.0.100`. You can do this:
70
+ You can allow single IP's or whole networks. Say you want to share your
71
+ console with `192.168.0.100`:
116
72
 
117
73
  ```ruby
118
74
  class Application < Rails::Application
119
- config.web_console.whitelisted_ips = '192.168.0.100'
75
+ config.web_console.permissions = '192.168.0.100'
120
76
  end
121
77
  ```
122
78
 
123
- If you want to whitelist the whole private network, you can do:
79
+ If you want to allow the whole private network:
124
80
 
125
81
  ```ruby
126
82
  Rails.application.configure do
127
- config.web_console.whitelisted_ips = '192.168.0.0/16'
83
+ config.web_console.permissions = '192.168.0.0/16'
128
84
  end
129
85
  ```
130
86
 
@@ -133,13 +89,13 @@ case in 2.0.
133
89
 
134
90
  ### config.web_console.whiny_requests
135
91
 
136
- When a console cannot be shown for a given IP address or content type, a
137
- messages like the following is printed in the server logs:
92
+ When a console cannot be shown for a given IP address or content type,
93
+ messages such as the following is printed in the server logs:
138
94
 
139
95
  > Cannot render console from 192.168.1.133! Allowed networks:
140
96
  > 127.0.0.0/127.255.255.255, ::1
141
97
 
142
- If you don't wanna see this message anymore, set this option to `false`:
98
+ If you don't want to see this message anymore, set this option to `false`:
143
99
 
144
100
  ```ruby
145
101
  Rails.application.configure do
@@ -149,7 +105,7 @@ end
149
105
 
150
106
  ### config.web_console.template_paths
151
107
 
152
- If you wanna style the console yourself, you can place `style.css` at a
108
+ If you want to style the console yourself, then you can place `style.css` at a
153
109
  directory pointed by `config.web_console.template_paths`:
154
110
 
155
111
  ```ruby
@@ -158,14 +114,14 @@ Rails.application.configure do
158
114
  end
159
115
  ```
160
116
 
161
- You may wanna check the [templates] folder at the source tree for the files you
117
+ You may want to check the [templates] folder at the source tree for the files you
162
118
  may override.
163
119
 
164
120
  ### config.web_console.mount_point
165
121
 
166
122
  Usually the middleware of _Web Console_ is mounted at `/__web_console`.
167
- If you wanna change the path for some reasons, you can specify it
168
- by `config.web_console.mount_point`:
123
+ If there is a need to change the path, then you can specify it by
124
+ `config.web_console.mount_point`:
169
125
 
170
126
  ```ruby
171
127
  Rails.application.configure do
@@ -177,27 +133,31 @@ end
177
133
 
178
134
  ### Where did /console go?
179
135
 
180
- The remote terminal emulator was extracted in its own gem that is no longer
136
+ The remote terminal emulator was extracted in its own gem which is no longer
181
137
  bundled with _Web Console_.
182
138
 
183
139
  If you miss this feature, check out [rvt].
184
140
 
185
- ### Why I constantly get unavailable session errors?
141
+ ### Why do I constantly get unavailable session errors?
186
142
 
187
143
  All of _Web Console_ sessions are stored in memory. If you happen to run on a
188
- multi-process server (like Unicorn) you may get unavailable session errors
144
+ multi-process server (like Unicorn), you may encounter unavailable session errors
189
145
  while the server is still running. This is because a request may hit a
190
146
  different worker (process) that doesn't have the desired session in memory.
191
-
192
147
  To avoid that, if you use such servers in development, configure them so they
193
- server requests only out of one process.
148
+ serve requests only out of one process.
149
+
150
+ #### Passenger
151
+
152
+ Enable sticky sessions for [Passenger on Nginx] or [Passenger on Apache] to
153
+ prevent unavailable session errors.
194
154
 
195
155
  ### How to inspect local and instance variables?
196
156
 
197
157
  The interactive console executes Ruby code. Invoking `instance_variables` and
198
158
  `local_variables` will give you what you want.
199
159
 
200
- ### Why does console only appear on error pages but not when I call it?
160
+ ### Why does the console only appear on error pages but not when I call it?
201
161
 
202
162
  This can be happening if you are using `Rack::Deflater`. Be sure that
203
163
  `WebConsole::Middleware` is used after `Rack::Deflater`. The easiest way to do
@@ -209,23 +169,25 @@ Rails.application.configure do
209
169
  end
210
170
  ```
211
171
 
212
- ### Why I'm getting an undefined method `web_console`?
172
+ ### Why am I getting an undefined method `web_console`?
213
173
 
214
- Make sure you configuration lives in `config/environments/development.rb`.
174
+ Make sure your configuration lives in `config/environments/development.rb`.
215
175
 
216
176
  ## Credits
217
177
 
218
- * Shoutout to [Charlie Somerville] for [better_errors] and [this] code.
219
- * Kudos to [John Mair] for [binding_of_caller].
178
+ * Shoutout to [Hailey Somerville] for [better_errors].
179
+ * Kudos to [John Mair] for [binding_of_caller] and [debug_inspector].
220
180
  * Thanks to [Charles Oliver Nutter] for all the _JRuby_ feedback.
221
- * Hugs and kisses to all of our [contributors].
181
+ * Hugs and kisses to all of our [contributors]!
222
182
 
223
- [better_errors]: https://github.com/charliesome/better_errors
183
+ [better_errors]: https://github.com/BetterErrors/better_errors
184
+ [debug_inspector]: https://github.com/banister/debug_inspector
224
185
  [binding_of_caller]: https://github.com/banister/binding_of_caller
225
- [Charlie Somerville]: https://github.com/charliesome
186
+ [Hailey Somerville]: https://github.com/haileys
226
187
  [John Mair]: https://github.com/banister
227
188
  [Charles Oliver Nutter]: https://github.com/headius
228
189
  [templates]: https://github.com/rails/web-console/tree/master/lib/web_console/templates
229
- [this]: https://github.com/rails/web-console/blob/master/lib/web_console/integration/cruby.rb#L20-L32
230
190
  [rvt]: https://github.com/gsamokovarov/rvt
231
191
  [contributors]: https://github.com/rails/web-console/graphs/contributors
192
+ [Passenger on Nginx]: https://www.phusionpassenger.com/library/config/nginx/reference/#passengerstickysessions
193
+ [Passenger on Apache]: https://www.phusionpassenger.com/library/config/apache/reference/#passengerstickysessions
data/Rakefile CHANGED
@@ -1,26 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
- require 'bundler/setup'
4
+ require "bundler/setup"
3
5
  rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
7
  end
6
8
 
7
- require 'socket'
8
- require 'rake/testtask'
9
- require 'tmpdir'
10
- require 'securerandom'
11
- require 'json'
12
- require 'web_console/testing/erb_precompiler'
9
+ require "socket"
10
+ require "rake/testtask"
11
+ require "tmpdir"
12
+ require "securerandom"
13
+ require "json"
14
+ require "web_console/testing/erb_precompiler"
13
15
 
14
16
  EXPANDED_CWD = File.expand_path(File.dirname(__FILE__))
15
17
 
16
18
  Rake::TestTask.new(:test) do |t|
17
- t.libs << 'lib'
18
- t.libs << 'test'
19
- t.pattern = 'test/**/*_test.rb'
19
+ t.libs << "lib"
20
+ t.libs << "test"
21
+ t.pattern = "test/**/*_test.rb"
20
22
  t.verbose = false
21
23
  end
22
24
 
23
- Dir['lib/web_console/tasks/**/*.rake'].each { |task| load task }
25
+ Dir["lib/web_console/tasks/**/*.rake"].each { |task| load task }
24
26
 
25
27
  Bundler::GemHelper.install_tasks
26
28
 
data/lib/web-console.rb CHANGED
@@ -1 +1,3 @@
1
- require 'web_console'
1
+ # frozen_string_literal: true
2
+
3
+ require "web_console"
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WebConsole
4
+ # A context lets you get object names related to the current session binding.
5
+ class Context
6
+ def initialize(binding)
7
+ @binding = binding
8
+ end
9
+
10
+ # Extracts entire objects which can be called by the current session unless
11
+ # the inputs is present.
12
+ #
13
+ # Otherwise, it extracts methods and constants of the object specified by
14
+ # the input.
15
+ def extract(input = nil)
16
+ input.present? ? local(input) : global
17
+ end
18
+
19
+ private
20
+
21
+ GLOBAL_OBJECTS = [
22
+ "instance_variables",
23
+ "local_variables",
24
+ "methods",
25
+ "class_variables",
26
+ "Object.constants",
27
+ "global_variables"
28
+ ]
29
+
30
+ def global
31
+ GLOBAL_OBJECTS.map { |cmd| eval(cmd) }
32
+ end
33
+
34
+ def local(input)
35
+ [
36
+ eval("#{input}.methods").map { |m| "#{input}.#{m}" },
37
+ eval("#{input}.constants").map { |c| "#{input}::#{c}" },
38
+ ]
39
+ end
40
+
41
+ def eval(cmd)
42
+ @binding.eval(cmd) rescue []
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebConsole
2
4
  # The base class for every Web Console related error.
3
5
  Error = Class.new(StandardError)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebConsole
2
4
  # Simple Ruby code evaluator.
3
5
  #
@@ -6,16 +8,23 @@ module WebConsole
6
8
  # return a string and will format exception output.
7
9
  class Evaluator
8
10
  # Cleanses exceptions raised inside #eval.
9
- cattr_reader :cleaner
10
- @@cleaner = ActiveSupport::BacktraceCleaner.new
11
- @@cleaner.add_silencer { |line| line.start_with?(File.expand_path('..', __FILE__)) }
11
+ cattr_reader :cleaner, default: begin
12
+ cleaner = ActiveSupport::BacktraceCleaner.new
13
+ cleaner.add_silencer { |line| line.start_with?(File.expand_path("..", __FILE__)) }
14
+ cleaner
15
+ end
12
16
 
13
17
  def initialize(binding = TOPLEVEL_BINDING)
14
18
  @binding = binding
15
19
  end
16
20
 
17
21
  def eval(input)
18
- "=> #{@binding.eval(input).inspect}\n"
22
+ # Binding#source_location is available since Ruby 2.6.
23
+ if @binding.respond_to? :source_location
24
+ "=> #{@binding.eval(input, *@binding.source_location).inspect}\n"
25
+ else
26
+ "=> #{@binding.eval(input).inspect}\n"
27
+ end
19
28
  rescue Exception => exc
20
29
  format_exception(exc)
21
30
  end
@@ -25,7 +34,7 @@ module WebConsole
25
34
  def format_exception(exc)
26
35
  backtrace = cleaner.clean(Array(exc.backtrace) - caller)
27
36
 
28
- format = "#{exc.class.name}: #{exc}\n"
37
+ format = "#{exc.class.name}: #{exc}\n".dup
29
38
  format << backtrace.map { |trace| "\tfrom #{trace}\n" }.join
30
39
  format
31
40
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WebConsole
4
+ class ExceptionMapper
5
+ attr_reader :exc
6
+
7
+ def self.follow(exc)
8
+ mappers = [new(exc)]
9
+
10
+ while cause = (cause || exc).cause
11
+ mappers << new(cause)
12
+ end
13
+
14
+ mappers
15
+ end
16
+
17
+ def self.find_binding(mappers, exception_object_id)
18
+ mappers.detect do |exception_mapper|
19
+ exception_mapper.exc.object_id == exception_object_id.to_i
20
+ end || mappers.first
21
+ end
22
+
23
+ def initialize(exception)
24
+ @backtrace = exception.backtrace
25
+ @bindings = exception.bindings
26
+ @exc = exception
27
+ end
28
+
29
+ def first
30
+ guess_the_first_application_binding || @bindings.first
31
+ end
32
+
33
+ def [](index)
34
+ guess_binding_for_index(index) || @bindings[index]
35
+ end
36
+
37
+ private
38
+
39
+ def guess_binding_for_index(index)
40
+ file, line = @backtrace[index].to_s.split(":")
41
+ line = line.to_i
42
+
43
+ @bindings.find do |binding|
44
+ source_location = SourceLocation.new(binding)
45
+ source_location.path == file && source_location.lineno == line
46
+ end
47
+ end
48
+
49
+ def guess_the_first_application_binding
50
+ @bindings.find do |binding|
51
+ source_location = SourceLocation.new(binding)
52
+ source_location.path.to_s.start_with?(Rails.root.to_s)
53
+ end
54
+ end
55
+ end
56
+ end