Module: RailsWithFirePHP::Common
- Included in:
- ActionDispatch::Response, CGI, HTTPResponse
- Defined in:
- lib/core/rails_with_firephp.rb
Constant Summary collapse
- RWFP_INIT_HEADERS =
FirePHP header template
{ 'X-Wf-Protocol-1' => 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2', 'X-Wf-1-Plugin-1' =>'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.2.0'}
- RWFP_INIT_HEADERS_LOG =
{ 'X-Wf-1-Structure-1' => 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1' }
- RWFP_INIT_HEADERS_DUMP =
{ 'X-Wf-1-Structure-2' => 'http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1' }
- RWFP_KINDS =
%w(LOG INFO WARN ERROR DUMP TRACE EXCEPTION TABLE)
- RWFP_LEGACY_WARNING =
{ 'X-FirePHP-Data-100000000001' => '{' , 'X-FirePHP-Data-300000000001' => '"FirePHP.Firebug.Console":[', 'X-FirePHP-Data-300000000002' => '[ "INFO", "This version of FirePHP is no longer supported by rwfp. Please update to 0.2.1 or higher." ],', 'X-FirePHP-Data-399999999999' => '["__SKIP__"]],', 'X-FirePHP-Data-999999999999' => '"__SKIP__":"__SKIP__"}' }
- MAX_LENGTH =
4000
Instance Method Summary collapse
-
#_rwfp_build_headers(msg, kind = 'LOG', label = nil) ⇒ Object
build header.
- #_rwfp_initialize_request(ua) ⇒ Object
-
#_rwfp_mask_ruby_types(data, skip = true) ⇒ Object
skip masking if not hash key.
- #_rwfp_set_options(opts) ⇒ Object
- #rwfp_internal_log(msg) ⇒ Object
-
#toUnicode(obj) ⇒ Object
from utf-8 to unicode.
Instance Method Details
#_rwfp_build_headers(msg, kind = 'LOG', label = nil) ⇒ Object
build header
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/core/rails_with_firephp.rb', line 23 def _rwfp_build_headers msg,kind='LOG',label=nil logheaders = [] t_pref,g_kind = kind == 'DUMP' ? [ 2, 'DUMP' ] : [ 1, 'LOG' ] file, line, function = caller[2].split ':' = { 'Type' => kind, 'File' => file, 'Line' => line } ['Label'] = label ? label + '(' + msg.class.to_s + ')' : '(' + msg.class.to_s + ')' #@fire_msg_index = 0 unless instance_variables.member? '@fire_msg_index' @fire_msg_index = 0 if not @fire_msg_index msg = _rwfp_mask_ruby_types( Marshal.load(Marshal.dump(msg)) ) if ( @rwfp_options.has_key? :mask_ruby_types && :mask_ruby_types ) msg_u = toUnicode msg.to_json label_u = toUnicode label.to_json = toUnicode .to_json msg = kind == 'DUMP' ? "{#{label_u}:#{msg_u}}" : "[#{},#{msg_u}]" (msg.gsub /.{#{MAX_LENGTH}}/ do |m| "#{m}\n" end).split( "\n" ).each_with_index do |msg_part,ind| @fire_msg_index += 1 logheaders << [ "X-Wf-1-#{t_pref}-1-#{@fire_msg_index}", "#{msg.size if ind == 0}|#{msg_part}|#{'\\' if ind < msg.size/MAX_LENGTH}" ] end unless instance_variables.member? "@rwfp_inited_#{g_kind.downcase}" RailsWithFirePHP::Common::const_get( "RWFP_INIT_HEADERS_#{g_kind}" ).each_pair { |k,v| logheaders << [ k, v ] } instance_variable_set( "@rwfp_inited_#{g_kind.downcase}", true ) end return logheaders end |
#_rwfp_initialize_request(ua) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/core/rails_with_firephp.rb', line 52 def _rwfp_initialize_request ua @firephp_version = ua.match( /FirePHP\/(\d+)\.(\d+)\.([\db.]+)/) @firephp_version = @firephp_version[1,3].map {|i| i.to_i} if @firephp_version firephp_01_version = ( @firephp_version || [0,2] )[0,2].join('.').to_f<0.2 @firephpruby_skip = @firephp_version == nil || firephp_01_version logheaders = firephp_01_version ? RWFP_LEGACY_WARNING : RWFP_INIT_HEADERS logheaders['X-FirePHP-RendererURL'] = @rwfp_options[:renderer_url] if @rwfp_options.has_key? :renderer_url logheaders['X-FirePHP-ProcessorURL'] = @rwfp_options[:processor_url] if @rwfp_options.has_key? :processor_url return logheaders end |
#_rwfp_mask_ruby_types(data, skip = true) ⇒ Object
skip masking if not hash key
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/core/rails_with_firephp.rb', line 70 def _rwfp_mask_ruby_types data, skip=true # skip masking if not hash key #rwfp_internal_log data.class.to_s if data.is_a? String return data elsif data.is_a? Integer return "__INT__#{data.to_s}__INT__" elsif data.is_a? Numeric return skip ? data : "__NUM__#{data.to_s}__NUM__" elsif data.is_a? TrueClass or data.is_a? FalseClass return skip ? data : "__BOOL__#{data.to_s}__BOOL__" elsif data.nil? return skip ? data : '__NIL__nil__NIL__' elsif data.is_a? Symbol return "__SYM__:#{data.to_s}__SYM__" elsif data.is_a? Array #rwfp_internal_log 'wird' return data.map { |v| _rwfp_mask_ruby_types v } elsif data.is_a? Hash k_types = [ Symbol, Fixnum, Bignum, Float, Range, TrueClass, FalseClass, NilClass ] j_types = [ Array, Hash ] data.each { |k,v| data[k] = _rwfp_mask_ruby_types v } keys_to_mask = data.keys.select { |k| k_types.include? k.class } keys_to_mask.each { |k| nk = _rwfp_mask_ruby_types k,false; data[nk] = data[k]; data.delete k } keys_to_jsonize = data.keys.select { |k| j_types.include? k.class } keys_to_jsonize.each do |k| nk = _rwfp_mask_ruby_types( k,false ).to_json data["__JSON__#{nk}__JSON__"] = data[k] data.delete k end return data elsif data.is_a? Range return "__RNG__#{data.to_s}__RNG__" end rwfp_internal_log 'shit happens - class: ' + data.class.to_s return data end |
#_rwfp_set_options(opts) ⇒ Object
47 48 49 50 |
# File 'lib/core/rails_with_firephp.rb', line 47 def opts @rwfp_options = {} unless instance_variables.member? '@rwfp_options' @rwfp_options.merge! opts end |
#rwfp_internal_log(msg) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/core/rails_with_firephp.rb', line 63 def rwfp_internal_log msg @fire_msg_index = 0 unless instance_variables.member? '@fire_msg_index' @fire_msg_index += 1 msg = "[#{{:Type=>'LOG',:Label=>'____________________________ internal message'}.to_json},#{msg.to_json}]" puts "X-Wf-1-1-1-#{@fire_msg_index}: #{msg.size}|#{msg}|" end |
#toUnicode(obj) ⇒ Object
from utf-8 to unicode
18 19 20 |
# File 'lib/core/rails_with_firephp.rb', line 18 def toUnicode obj obj.unpack('U*').map {|i| i>=592 ? ("\\u" + i.to_s(16).rjust(4, '0')) : [i].pack('U') }.join end |