rack-var-dump 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -67
- data/lib/rack/var_dump.rb +11 -14
- data/lib/rack/var_dump/object.rb +2 -2
- data/lib/rack/var_dump/version.rb +1 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -1,75 +1,12 @@
|
|
1
1
|
(書きかけ)
|
2
2
|
|
3
|
-
|
4
|
-
= rack-var-dump
|
5
|
-
|
6
|
-
rack-var-dump provides a method for debugging like var_dump() of php.
|
7
|
-
|
8
|
-
By the time it provides Object Class with a var_dump method and returns a response, they are Model, Controller, and View,
|
9
|
-
|
10
|
-
All the receivers performed by others or the given argument is automatically outputted to View.
|
11
|
-
|
12
|
-
== Supported versions
|
13
|
-
|
14
|
-
* Ruby 1.8.7, 1.9.x
|
15
|
-
|
16
|
-
* Using Rack (rails, sinatra, padrino, etc...)
|
17
|
-
|
18
|
-
== Install
|
19
|
-
|
20
|
-
$ gem install rack-var-dump
|
21
|
-
|
22
|
-
=== Rails
|
23
|
-
|
24
|
-
Put this line in your Gemfile:
|
25
|
-
gem 'rack-var-dump'
|
26
|
-
|
27
|
-
Bundle Install
|
28
|
-
% bundle install
|
29
|
-
|
30
|
-
=== Rails3.x
|
31
|
-
|
32
|
-
Put this line in your config/application.rb
|
33
|
-
require 'rails-var-dump'
|
34
|
-
|
35
|
-
=== Others application using Rack
|
36
|
-
|
37
|
-
Require rack/var_dump.
|
38
|
-
require 'rack/var_dump'
|
39
|
-
|
40
|
-
Please use Rack::VarDump
|
41
|
-
use Rack::VarDump
|
42
|
-
|
43
|
-
== How to use
|
44
|
-
|
45
|
-
When requiring rails-var-dump or rack/var_dump,
|
46
|
-
|
47
|
-
all the objects are provided with
|
48
|
-
|
49
|
-
var_dump (var = nil).
|
50
|
-
|
51
|
-
=== e.g.
|
52
|
-
@users = User.all.var_dump
|
53
|
-
var_dump(@users)
|
54
|
-
|
55
|
-
The return value of var_dump can always be used for self,
|
56
|
-
|
57
|
-
without a chain breaking off.
|
58
|
-
|
59
|
-
@first_name = User.find(3).var_dump.first_name
|
60
|
-
|
61
|
-
== Copyright
|
62
|
-
|
63
|
-
Copyright (c) 2012 Daichi Hirata. See LICENSE for details.
|
64
|
-
|
65
|
-
|
66
3
|
= Japanese
|
67
4
|
|
68
5
|
rack-var-dumpはphpのvar_dump()のようなデバッグ用のメソッドを提供します
|
69
6
|
|
70
7
|
Object Classにvar_dumpメソッドを提供し、レスポンスを返すまでにModel,Controller,View,
|
71
8
|
|
72
|
-
|
9
|
+
その他で実行されたすべてのレシーバーをviewに自動的に出力します
|
73
10
|
|
74
11
|
var_dumpの返り値は常にselfです
|
75
12
|
|
@@ -108,15 +45,15 @@ Rack::VarDumpミドルウェアをuse
|
|
108
45
|
== 使い方
|
109
46
|
|
110
47
|
rails-var-dumpもしくはrack/var_dumpをrequireしている場合、全てのオブジェクトに
|
111
|
-
var_dump(
|
48
|
+
var_dump(subject = nil)
|
112
49
|
が提供されています
|
113
50
|
|
114
51
|
=== 例
|
115
52
|
@users = User.all.var_dump
|
116
|
-
var_dump(
|
53
|
+
@users.var_dump("user.all")
|
117
54
|
|
118
55
|
var_dumpの返り値は常にselfのため、チェーンが途切れずに使用できます
|
119
|
-
@first_name = User.find(3).var_dump.first_name
|
56
|
+
@first_name = User.find(3).var_dump('user.id(3)').first_name
|
120
57
|
|
121
58
|
|
122
59
|
== Copyright
|
data/lib/rack/var_dump.rb
CHANGED
@@ -8,16 +8,8 @@ module Rack
|
|
8
8
|
|
9
9
|
@@var_aggregates = []
|
10
10
|
|
11
|
-
def self.var_dump(var)
|
12
|
-
@@var_aggregates << var.
|
13
|
-
rescue => e
|
14
|
-
if defined?(Rails)
|
15
|
-
::Rails.logger.warn "Rack::VarDump[warn] #{e}"
|
16
|
-
end
|
17
|
-
|
18
|
-
if var.respond_to?(:inspect)
|
19
|
-
@@var_aggregates << var.inspect
|
20
|
-
end
|
11
|
+
def self.var_dump(var, subject)
|
12
|
+
@@var_aggregates << {:var => var.inspect, :subject => subject}
|
21
13
|
end
|
22
14
|
|
23
15
|
def self.reset!
|
@@ -26,6 +18,7 @@ module Rack
|
|
26
18
|
|
27
19
|
def initialize(app)
|
28
20
|
@app = app
|
21
|
+
VarDump.reset!
|
29
22
|
end
|
30
23
|
|
31
24
|
def call(env)
|
@@ -44,10 +37,14 @@ module Rack
|
|
44
37
|
|
45
38
|
private
|
46
39
|
def apply(request, response)
|
47
|
-
html =
|
48
|
-
html <<
|
49
|
-
|
50
|
-
|
40
|
+
html = '<div id="var_dump" style="display:block">'
|
41
|
+
html << '<pre style="background-color:#eee;padding:10px;font-size:11px;white-space:pre-wrap;color:black!important;">'
|
42
|
+
@@var_aggregates.each_with_index do |info, n|
|
43
|
+
html << "var_dump:#{n} #{info[:subject]}\n"
|
44
|
+
html << Rack::Utils.escape_html(info[:var])
|
45
|
+
html << "\n\n"
|
46
|
+
end
|
47
|
+
html << "</pre></div>"
|
51
48
|
response.sub(/<body.*>/, '\&' + html)
|
52
49
|
end
|
53
50
|
end
|
data/lib/rack/var_dump/object.rb
CHANGED