web-console 3.0.0 → 3.1.1

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
  SHA1:
3
- metadata.gz: 3ed4f368321b193eeb169e5c5fc82db4b704cbaa
4
- data.tar.gz: db55b7d89f828ec70974bd9ed46d19e8509f001c
3
+ metadata.gz: 35b84addef5e3e76f47e06e3c18582721dd344f1
4
+ data.tar.gz: 2089aca773c3f118ef93ecea2084838da6c69951
5
5
  SHA512:
6
- metadata.gz: 196f9a54b30873b3838c8798f02803fc850af578812c84cc32bf5faccc7e8decc33cb878048e899d9bf4cf0c13415b52edbd042f19ba9c4654e1a784b1961e59
7
- data.tar.gz: 9927a7e855ceeccfca83ca490bacf8392f8c55fedf2291ecc87f17d51437b7eea35cfe04e050ec6f52eee5d14e793248383c4e670904e4253a43ac96c6284541
6
+ metadata.gz: 3d9e288ce24ad68f578d87bc9a5de25678defe0e82b1af6e3d22adc0d4aee394df5f369f0eb8c036bf437b24103db2086c97abe8aaf2b98a5690c416daf2abe4
7
+ data.tar.gz: deb6c9fb3bce25afbc4e446b660a8b6dc7d47698fd8dae4933be7b96080d00115940a3b614e9eec822563da4fef800037fc9db7768bfad34b856eabbe04776f7
data/CHANGELOG.markdown CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 3.1.1
6
+
7
+ * [#185](https://github.com/rails/web-console/pull/185) Fix `rails console` startup ([@gsamokovarov])
8
+
9
+ ## 3.1.0
10
+
11
+ * [#182](https://github.com/rails/web-console/pull/182) Let `#console` live in `Kernel` ([@schneems])
12
+ * [#181](https://github.com/rails/web-console/pull/181) Log internal Web Console errors ([@gsamokovarov])
13
+ * [#180](https://github.com/rails/web-console/pull/180) Autoload Web Console constants for faster Rails boot time ([@herminiotorres])
14
+
5
15
  ## 3.0.0
6
16
 
7
17
  * [#173](https://github.com/rails/web-console/pull/173) Revert "Change config.development_only default until 4.2.4 is released" ([@gsamokovarov])
@@ -55,3 +65,5 @@
55
65
  [@parterburn]: https://github.com/parterburn
56
66
  [@sh19910711]: https://github.com/sh19910711
57
67
  [@frenesim]: https://github.com/frenesim
68
+ [@herminiotorres]: https://github.com/herminiotorres
69
+ [@schneems]: https://github.com/schneems
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2014 Charlie Somerville, Genadi Samokovarov, Guillermo Iguaran and Ryan Dao
1
+ Copyright 2014-2016 Charlie 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,7 +1,8 @@
1
1
  <p align=right>
2
2
  Documentation for:
3
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.1.3>v2.1.3</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.0.0>v3.0.0</a>
5
6
  </p>
6
7
 
7
8
  # Web Console [![Build Status](https://travis-ci.org/rails/web-console.svg?branch=master)](https://travis-ci.org/rails/web-console)
@@ -67,8 +68,10 @@ class PostsController < ApplicationController
67
68
  end
68
69
  ```
69
70
 
70
- Only one `console` invocation is allowed per request. If you happen to have
71
- multiple ones, a `WebConsole::DoubleRenderError` is raised.
71
+ The method is defined in `Kernel` and you can invoke it any application code.
72
+
73
+ Only one `console` invocation is allowed once per request. If you happen to
74
+ have multiple ones, a `WebConsole::DoubleRenderError` will be raised.
72
75
 
73
76
  ## Configuration
74
77
 
data/lib/web_console.rb CHANGED
@@ -1,23 +1,29 @@
1
+ require 'active_support/dependencies/autoload'
1
2
  require 'active_support/lazy_load_hooks'
2
3
  require 'active_support/logger'
3
4
 
4
- require 'web_console/integration'
5
- require 'web_console/railtie'
6
- require 'web_console/errors'
7
- require 'web_console/helper'
8
- require 'web_console/evaluator'
9
- require 'web_console/session'
10
- require 'web_console/template'
11
- require 'web_console/middleware'
12
- require 'web_console/whitelist'
13
- require 'web_console/request'
14
- require 'web_console/response'
15
- require 'web_console/view'
16
- require 'web_console/whiny_request'
17
-
18
5
  module WebConsole
6
+ extend ActiveSupport::Autoload
7
+
8
+ autoload :View
9
+ autoload :Evaluator
10
+ autoload :Session
11
+ autoload :Response
12
+ autoload :Request
13
+ autoload :WhinyRequest
14
+ autoload :Whitelist
15
+ autoload :Template
16
+ autoload :Middleware
17
+
18
+ autoload_at 'web_console/errors' do
19
+ autoload :Error
20
+ autoload :DoubleRenderError
21
+ end
22
+
19
23
  mattr_accessor :logger
20
24
  @@logger = ActiveSupport::Logger.new($stderr)
21
25
 
22
26
  ActiveSupport.run_load_hooks(:web_console, self)
23
27
  end
28
+
29
+ require 'web_console/railtie'
@@ -1,24 +1,48 @@
1
- ActionDispatch::DebugExceptions.class_eval do
2
- def render_exception_with_web_console(request, exception)
3
- render_exception_without_web_console(request, exception).tap do
4
- # Retain superficial Rails 4.2 compatibility.
5
- env = Hash === request ? request : request.env
6
-
7
- backtrace_cleaner = env['action_dispatch.backtrace_cleaner']
8
- error = ActionDispatch::ExceptionWrapper.new(backtrace_cleaner, exception).exception
9
-
10
- # Get the original exception if ExceptionWrapper decides to follow it.
11
- env['web_console.exception'] = error
12
-
13
- # ActionView::Template::Error bypass ExceptionWrapper original
14
- # exception following. The backtrace in the view is generated from
15
- # reaching out to original_exception in the view.
16
- if error.is_a?(ActionView::Template::Error)
17
- env['web_console.exception'] = error.original_exception
1
+ module Kernel
2
+ module_function
3
+
4
+ # Instructs Web Console to render a console in the specified binding.
5
+ #
6
+ # If +bidning+ isn't explicitly given it will default to the binding of the
7
+ # previous frame. E.g. the one that invoked +console+.
8
+ #
9
+ # Raises DoubleRenderError if a double +console+ invocation per request is
10
+ # detected.
11
+ def console(binding = WebConsole.caller_bindings.first)
12
+ raise WebConsole::DoubleRenderError if Thread.current[:__web_console_binding]
13
+
14
+ Thread.current[:__web_console_binding] = binding
15
+
16
+ # Make sure nothing is rendered from the view helper. Otherwise
17
+ # you're gonna see unexpected #<Binding:0x007fee4302b078> in the
18
+ # templates.
19
+ nil
20
+ end
21
+ end
22
+
23
+ module ActionDispatch
24
+ class DebugExceptions
25
+ def render_exception_with_web_console(request, exception)
26
+ render_exception_without_web_console(request, exception).tap do
27
+ # Retain superficial Rails 4.2 compatibility.
28
+ env = Hash === request ? request : request.env
29
+
30
+ backtrace_cleaner = env['action_dispatch.backtrace_cleaner']
31
+ error = ExceptionWrapper.new(backtrace_cleaner, exception).exception
32
+
33
+ # Get the original exception if ExceptionWrapper decides to follow it.
34
+ Thread.current[:__web_console_exception] = error
35
+
36
+ # ActionView::Template::Error bypass ExceptionWrapper original
37
+ # exception following. The backtrace in the view is generated from
38
+ # reaching out to original_exception in the view.
39
+ if error.is_a?(ActionView::Template::Error)
40
+ Thread.current[:__web_console_exception] = error.cause
41
+ end
18
42
  end
19
43
  end
20
- end
21
44
 
22
- alias_method :render_exception_without_web_console, :render_exception
23
- alias_method :render_exception, :render_exception_with_web_console
45
+ alias_method :render_exception_without_web_console, :render_exception
46
+ alias_method :render_exception, :render_exception_with_web_console
47
+ end
24
48
  end
@@ -19,7 +19,7 @@ class Exception
19
19
  #
20
20
  # Every integration should the instance variable.
21
21
  def bindings
22
- @bindings || []
22
+ (defined?(@bindings) && @bindings) || []
23
23
  end
24
24
  end
25
25
 
@@ -15,34 +15,40 @@ module WebConsole
15
15
  end
16
16
 
17
17
  def call(env)
18
- request = create_regular_or_whiny_request(env)
19
- return @app.call(env) unless request.from_whitelisted_ip?
18
+ app_exception = catch :app_exception do
19
+ request = create_regular_or_whiny_request(env)
20
+ return call_app(env) unless request.from_whitelisted_ip?
21
+
22
+ if id = id_for_repl_session_update(request)
23
+ return update_repl_session(id, request)
24
+ elsif id = id_for_repl_session_stack_frame_change(request)
25
+ return change_stack_trace(id, request)
26
+ end
20
27
 
21
- if id = id_for_repl_session_update(request)
22
- return update_repl_session(id, request)
23
- elsif id = id_for_repl_session_stack_frame_change(request)
24
- return change_stack_trace(id, request)
25
- end
28
+ status, headers, body = call_app(env)
26
29
 
27
- status, headers, body = @app.call(env)
30
+ if session = Session.from(Thread.current) and acceptable_content_type?(headers)
31
+ response = Response.new(body, status, headers)
32
+ template = Template.new(env, session)
28
33
 
29
- if exception = env['web_console.exception']
30
- session = Session.from_exception(exception)
31
- elsif binding = env['web_console.binding']
32
- session = Session.from_binding(binding)
34
+ response.headers["X-Web-Console-Session-Id"] = session.id
35
+ response.headers["X-Web-Console-Mount-Point"] = mount_point
36
+ response.write(template.render('index'))
37
+ response.finish
38
+ else
39
+ [ status, headers, body ]
40
+ end
33
41
  end
42
+ rescue => e
43
+ WebConsole.logger.error("\n#{e.class}: #{e}\n\tfrom #{e.backtrace.join("\n\tfrom ")}")
44
+ raise e
45
+ ensure
46
+ # Clean up the fiber locals after the session creation. Object#console
47
+ # uses those to communicate the current binding or exception to the middleware.
48
+ Thread.current[:__web_console_exception] = nil
49
+ Thread.current[:__web_console_binding] = nil
34
50
 
35
- if session && acceptable_content_type?(headers)
36
- response = Response.new(body, status, headers)
37
- template = Template.new(env, session)
38
-
39
- response.headers["X-Web-Console-Session-Id"] = session.id
40
- response.headers["X-Web-Console-Mount-Point"] = mount_point
41
- response.write(template.render('index'))
42
- response.finish
43
- else
44
- [ status, headers, body ]
45
- end
51
+ raise app_exception if Exception === app_exception
46
52
  end
47
53
 
48
54
  private
@@ -120,5 +126,11 @@ module WebConsole
120
126
  { output: I18n.t('errors.unacceptable_request') }
121
127
  end
122
128
  end
129
+
130
+ def call_app(env)
131
+ @app.call(env)
132
+ rescue => e
133
+ throw :app_exception, e
134
+ end
123
135
  end
124
136
  end
@@ -6,14 +6,11 @@ module WebConsole
6
6
  config.web_console.whitelisted_ips = %w( 127.0.0.1 ::1 )
7
7
 
8
8
  initializer 'web_console.initialize' do
9
+ require 'web_console/integration'
9
10
  require 'web_console/extensions'
10
11
 
11
- ActiveSupport.on_load(:action_view) do
12
- ActionView::Base.send(:include, Helper)
13
- end
14
-
15
- ActiveSupport.on_load(:action_controller) do
16
- ActionController::Base.send(:include, Helper)
12
+ if logger = ::Rails.logger
13
+ WebConsole.logger = logger
17
14
  end
18
15
  end
19
16
 
@@ -1,9 +1,9 @@
1
1
  module WebConsole
2
- # A session lets you persist wrap an +Evaluator+ instance in memory
3
- # associated with multiple bindings.
2
+ # A session lets you persist an +Evaluator+ instance in memory associated
3
+ # with multiple bindings.
4
4
  #
5
5
  # Each newly created session is persisted into memory and you can find it
6
- # later its +id+.
6
+ # later by its +id+.
7
7
  #
8
8
  # A session may be associated with multiple bindings. This is used by the
9
9
  # error pages only, as currently, this is the only client that needs to do
@@ -21,14 +21,19 @@ module WebConsole
21
21
  inmemory_storage[id]
22
22
  end
23
23
 
24
- # Create a Session from an exception.
25
- def from_exception(exc)
26
- new(exc.bindings)
27
- end
28
-
29
- # Create a Session from a single binding.
30
- def from_binding(binding)
31
- new(binding)
24
+ # Create a Session from an binding or exception in a storage.
25
+ #
26
+ # The storage is expected to respond to #[]. The binding is expected in
27
+ # :__web_console_binding and the exception in :__web_console_exception.
28
+ #
29
+ # Can return nil, if no binding or exception have been preserved in the
30
+ # storage.
31
+ def from(storage)
32
+ if exc = storage[:__web_console_exception]
33
+ new(exc.bindings)
34
+ elsif binding = storage[:__web_console_binding]
35
+ new(binding)
36
+ end
32
37
  end
33
38
  end
34
39
 
@@ -1,3 +1,3 @@
1
1
  module WebConsole
2
- VERSION = '3.0.0'
2
+ VERSION = '3.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web-console
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Somerville
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-12-13 00:00:00.000000000 Z
14
+ date: 2016-01-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: railties
@@ -74,7 +74,6 @@ files:
74
74
  - lib/web_console/errors.rb
75
75
  - lib/web_console/evaluator.rb
76
76
  - lib/web_console/extensions.rb
77
- - lib/web_console/helper.rb
78
77
  - lib/web_console/integration.rb
79
78
  - lib/web_console/integration/cruby.rb
80
79
  - lib/web_console/integration/rubinius.rb
@@ -100,7 +99,6 @@ files:
100
99
  - lib/web_console/testing/erb_precompiler.rb
101
100
  - lib/web_console/testing/fake_middleware.rb
102
101
  - lib/web_console/testing/helper.rb
103
- - lib/web_console/tracer.rb
104
102
  - lib/web_console/version.rb
105
103
  - lib/web_console/view.rb
106
104
  - lib/web_console/whiny_request.rb
@@ -125,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
123
  version: '0'
126
124
  requirements: []
127
125
  rubyforge_project:
128
- rubygems_version: 2.4.5
126
+ rubygems_version: 2.5.1
129
127
  signing_key:
130
128
  specification_version: 4
131
129
  summary: A debugging tool for your Ruby on Rails applications.
@@ -1,22 +0,0 @@
1
- module WebConsole
2
- module Helper
3
- # Communicates with the middleware to render a console in a +binding+.
4
- #
5
- # If +bidning+ isn't explicitly given, Binding#of_caller will be used to
6
- # get the binding of the previous frame. E.g. the one that invoked
7
- # +console+.
8
- #
9
- # Raises DoubleRenderError if a double +console+ invocation per request is
10
- # detected.
11
- def console(binding = nil)
12
- raise DoubleRenderError if request.env['web_console.binding']
13
-
14
- request.env['web_console.binding'] = binding || ::WebConsole.caller_bindings.first
15
-
16
- # Make sure nothing is rendered from the view helper. Otherwise
17
- # you're gonna see unexpected #<Binding:0x007fee4302b078> in the
18
- # templates.
19
- nil
20
- end
21
- end
22
- end
@@ -1,11 +0,0 @@
1
- module WebConsole
2
- class BindingTracer
3
- def initialize(exception)
4
- @bindings = exception.bindings
5
- @backtrace = exception.backtrace
6
- end
7
-
8
- def binding_for_trace(trace)
9
- end
10
- end
11
- end