fix bug for can't launch console #1

Closed
wants to merge 1 commit into
from

Projects

None yet

3 participants

@ainame
ainame commented Sep 17, 2012

I found a bug that we can't lauch web console.
'5f20c5c46aed410df917f0588818fe9d6a92413b' commit cause a bug
for javascript. When I use rack-webconsole by deafult setting,
Rack::Webconsole.key_code return "96". But, Rack::Webconsole
class's spec says Rack::Webconsole.key_code should return "[96]",
after setting value, or else webconsole.js has error that
following code.

if ( 96.indexOf(event.which) >= 0 ) {
...

Then, I have changed initializing of @@config to using
Rack::Webconsole.key_code and Rack::Webconsole.inject_jquery
methods at lib/rack/webconsole.rb. So, @@config[:key_code]
will initialize by Rack::Webconsole.key_code, and
Rack::Webconsole.key_code will return "[96]".

Satoshi Namai fix bug for can't launch console
I found a bug that we can't lauch web console.
'5f20c5c46aed410df917f0588818fe9d6a92413b' commit cause a bug
for javascript. When I use rack-webconsole by deafult setting,
Rack::Webconsole.key_code return "96". But, Rack::Webconsole
class's spec says Rack::Webconsole.key_code should return "[96]",
after setting value, or else webconsole.js has error that
following code.

  if ( 96.indexOf(event.which) >= 0 ) {
    ...

Then, I have changed initializing of @@config to using
Rack::Webconsole.key_code and Rack::Webconsole.inject_jquery
methods at lib/rack/webconsole.rb. So, @@config[:key_code]
will initialize by Rack::Webconsole.key_code, and
Rack::Webconsole.key_code will return "[96]".
36bb528
@r7kamura

How about defining Rack::Webconsole.config instead of referring @@config directly?

diff --git a/lib/rack/webconsole.rb b/lib/rack/webconsole.rb
index 3e7577b..da72635 100644
--- a/lib/rack/webconsole.rb
+++ b/lib/rack/webconsole.rb
@@ -23,41 +23,48 @@ module Rack
   # variables and giving a true IRB-esque experience.
   #
   class Webconsole
-    @@config = {:inject_jquery => false, :key_code => "96"}
-
     class << self
       # Returns whether the Asset injecter must inject JQuery or not.
       #
       # @return [Boolean] whether to inject JQuery or not.
       def inject_jquery
-        @@config[:inject_jquery]
+        config[:inject_jquery]
       end

       # Sets whether the Asset injecter must inject JQuery or not.
       #
       # @param [Boolean] value whether to inject JQuery or not.
       def inject_jquery=(value)
-        @@config[:inject_jquery] = value
+        config[:inject_jquery] = value
       end

       # Returns key code used to start web console.
       #
       # @return [String] key code used at keypress event to start web console.
       def key_code
-        @@config[:key_code]
+        config[:key_code]
       end

       # Sets key code used to start web console.
       #
       # @param [String] value key code used at keypress event to start web console.
       def key_code=(value)
-        value = [value] unless value.kind_of?(Array)
-        value.map! {|v| v.to_i }
-        value = MultiJson::encode(value)
-        @@config[:key_code] = value
+        values = Array(value)
+        codes  = values.map(&:to_i)
+        json   = MultiJson::encode(codes)
+        config[:key_code] = json
+      end
+
+      private
+
+      def config
+        @config ||= {}
       end
     end

+    self.inject_jquery = false
+    self.key_code = "96"
+
     # Honor the Rack contract by saving the passed Rack application in an ivar.
     #
     # @param [Rack::Application] app the previous Rack application in the
@mrbrdo mrbrdo added a commit that referenced this pull request Sep 17, 2012
@mrbrdo fix issue #1 110a54d
@mrbrdo mrbrdo closed this Sep 17, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment