rack-var-dump 0.1.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -4
- data/lib/rack/var_dump.rb +29 -17
- data/lib/rack/var_dump/awesome_print.rb +2 -0
- data/lib/rack/var_dump/awesome_print/ext/var_dump.rb +14 -0
- data/lib/rack/var_dump/awesome_print/ext/var_dump.rb.old +21 -0
- data/lib/rack/var_dump/kernel.rb +6 -0
- data/lib/rack/var_dump/object.rb +4 -14
- data/lib/rack/var_dump/railtie.rb +12 -0
- data/lib/rack/var_dump/version.rb +1 -1
- data/lib/rails-var-dump.rb +1 -1
- data/lib/rails_var_dump.rb +1 -1
- data/rack-var-dump.gemspec +3 -2
- data/spec/middleware_spec.rb +4 -4
- metadata +25 -21
- data/lib/rack/railtie.rb +0 -16
data/README.md
CHANGED
@@ -10,13 +10,13 @@ Writing now...
|
|
10
10
|
|
11
11
|
rack-var-dumpはphpのvar_dump()のようなデバッグ用のメソッドを提供します
|
12
12
|
|
13
|
-
Object
|
13
|
+
Objectにvar_dumpメソッドを提供し、Rackがレスポンスを返すまでにModel,Controller,View,
|
14
14
|
|
15
|
-
|
15
|
+
その他コンテキストで実行されたすべてのレシーバーをviewに自動的に出力します
|
16
16
|
|
17
|
-
|
17
|
+
出力には michaeldv / awesome_print を使用しています。
|
18
18
|
|
19
|
-
<img src="http://cdn-ak.f.st-hatena.com/images/fotolife/b/bunnyhop/
|
19
|
+
<img src="http://cdn-ak.f.st-hatena.com/images/fotolife/b/bunnyhop/20120208/20120208182805.png"/>
|
20
20
|
|
21
21
|
## Supported versions
|
22
22
|
|
data/lib/rack/var_dump.rb
CHANGED
@@ -1,19 +1,29 @@
|
|
1
1
|
require "rack/utils"
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require 'rack/var_dump/kernel'
|
3
|
+
require 'rack/var_dump/version'
|
4
|
+
require 'rack/var_dump/awesome_print'
|
4
5
|
|
5
6
|
module Rack
|
6
7
|
class VarDump
|
7
|
-
include Object
|
8
|
-
|
9
8
|
@@var_aggregates = []
|
10
9
|
|
10
|
+
def self.reset!
|
11
|
+
@@var_aggregates = []
|
12
|
+
end
|
13
|
+
|
11
14
|
def self.var_dump(var, subject)
|
12
|
-
@@var_aggregates <<
|
15
|
+
@@var_aggregates <<
|
16
|
+
{ :var => ai(var, :html => true), :subject => subject }
|
13
17
|
end
|
14
18
|
|
15
|
-
def self.
|
16
|
-
|
19
|
+
def self.ai(var, options = {})
|
20
|
+
ap = AwesomePrint::Inspector.new(options)
|
21
|
+
ap.instance_eval do
|
22
|
+
formatter = AwesomePrint::VarDump.new(self)
|
23
|
+
instance_variable_set(:@formatter, formatter)
|
24
|
+
end
|
25
|
+
|
26
|
+
ap.awesome(var)
|
17
27
|
end
|
18
28
|
|
19
29
|
def initialize(app)
|
@@ -30,21 +40,23 @@ module Rack
|
|
30
40
|
response = [apply(body)] if body =~ /<body.*>/
|
31
41
|
headers["Content-Length"] = response.join.bytesize.to_s
|
32
42
|
end
|
43
|
+
|
33
44
|
VarDump.reset!
|
34
45
|
[status, headers, response]
|
35
46
|
end
|
36
47
|
|
37
48
|
private
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
49
|
+
def apply(body)
|
50
|
+
html = '<div id="var_dump" style="display:block">'
|
51
|
+
html << '<pre style="background-color:#eee;padding:10px;font-size:11px;white-space:pre-wrap;color:black!important;">'
|
52
|
+
@@var_aggregates.each_with_index do |info, n|
|
53
|
+
html << "var_dump:#{n} #{info[:subject]}\n"
|
54
|
+
html << info[:var]
|
55
|
+
html << "\n\n"
|
56
|
+
end
|
57
|
+
html << "</pre></div>"
|
58
|
+
|
59
|
+
body.sub(/<body.*>/, '\&' + html)
|
45
60
|
end
|
46
|
-
html << "</pre></div>"
|
47
|
-
body.sub(/<body.*>/, '\&' + html)
|
48
|
-
end
|
49
61
|
end
|
50
62
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module AwesomePrint
|
2
|
+
class VarDump < Formatter
|
3
|
+
def format(object, type = nil)
|
4
|
+
core_class = cast(object, type)
|
5
|
+
|
6
|
+
awesome = if core_class != :self
|
7
|
+
send(:"awesome_#{core_class}", object) # Core formatters.
|
8
|
+
else
|
9
|
+
awesome_self(object, type) # Catch all that falls back to object.inspect.
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module AwesomePrint
|
2
|
+
module VarDump
|
3
|
+
def self.included(base)
|
4
|
+
base.send :alias_method, :format_without_var_dump, :format
|
5
|
+
base.send :alias_method, :format, :format_with_var_dump
|
6
|
+
end
|
7
|
+
|
8
|
+
def format_with_var_dump(object, type = nil)
|
9
|
+
core_class = cast(object, type)
|
10
|
+
awesome = if core_class != :self
|
11
|
+
send(:"awesome_#{core_class}", object)
|
12
|
+
else
|
13
|
+
awesome_self(object, type)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
AwesomePrint::Formatter.send(:include, AwesomePrint::VarDump)
|
20
|
+
|
21
|
+
|
data/lib/rack/var_dump/object.rb
CHANGED
@@ -1,17 +1,7 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
def self.included(obj)
|
5
|
-
::Object.send(:include, Method)
|
6
|
-
::Object.extend(Method)
|
7
|
-
end
|
8
|
-
end
|
1
|
+
module Object
|
2
|
+
def var_dump(subject = nil)
|
3
|
+
Rack::VarDump.var_dump(self, subject)
|
9
4
|
|
10
|
-
|
11
|
-
def var_dump(subject = nil)
|
12
|
-
Rack::VarDump.var_dump(self, subject)
|
13
|
-
self
|
14
|
-
end
|
15
|
-
end
|
5
|
+
self
|
16
6
|
end
|
17
7
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'rack/var_dump'
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
class VarDump
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
initializer "rack_var_dump.use_middleware" do |app|
|
8
|
+
app.middleware.use ::Rack::VarDump if ENV['RAILS_ENV'] == "development"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/rails-var-dump.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'rack/railtie' if defined?(Rails)
|
1
|
+
require 'rack/var_dump/railtie' if defined?(Rails)
|
data/lib/rails_var_dump.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require '
|
1
|
+
require 'rails-var-dump'
|
data/rack-var-dump.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Dach_h"]
|
9
9
|
s.email = ["bunny.hop.md@gmail.com"]
|
10
10
|
s.homepage = ""
|
11
|
-
s.summary = %q{
|
11
|
+
s.summary = %q{provides a method for debugging like var_dump() of php.}
|
12
12
|
s.description = s.summary
|
13
13
|
s.rubyforge_project = "rack-var-dump"
|
14
14
|
s.files = `git ls-files`.split("\n")
|
@@ -16,8 +16,9 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
+
s.add_dependency 'awesome_print', '= 1.0.2'
|
20
|
+
|
19
21
|
s.add_development_dependency 'rake', '>= 0.9.2.2'
|
20
|
-
s.add_development_dependency 'rdoc', '>= 3.11'
|
21
22
|
s.add_development_dependency "rack", '>= 1.3.5'
|
22
23
|
s.add_development_dependency 'rack-test', '>= 0.5.3'
|
23
24
|
s.add_development_dependency 'rspec', '>= 2.7.0'
|
data/spec/middleware_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe 'VarDump' do
|
|
8
8
|
describe "when var_dump is performed" do
|
9
9
|
before { 'sample-text'.var_dump }
|
10
10
|
let(:insert_html) do
|
11
|
-
%Q
|
11
|
+
%Q(var_dump:0 \n<kbd style=\"color:brown\">"sample-text"</kbd>)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "it is inserted when a status code is 200." do
|
@@ -25,7 +25,7 @@ describe 'VarDump' do
|
|
25
25
|
describe "when an argument is given" do
|
26
26
|
before { 'sample-text'.var_dump('Rspec:String') }
|
27
27
|
let(:insert_html) do
|
28
|
-
%Q
|
28
|
+
%Q(var_dump:0 Rspec:String\n<kbd style=\"color:brown\">"sample-text"</kbd>)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "It displays with subject." do
|
@@ -37,7 +37,7 @@ describe 'VarDump' do
|
|
37
37
|
describe "when the two or more sets value is carried out" do
|
38
38
|
before{'sample-text'.var_dump; 'sample-text-2'.var_dump('Rspec:String2')}
|
39
39
|
let(:insert_html) do
|
40
|
-
%Q
|
40
|
+
%Q(var_dump:0 \n<kbd style=\"color:brown\">"sample-text"</kbd>\n\nvar_dump:1 Rspec:String2\n<kbd style=\"color:brown\">"sample-text-2"</kbd>)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "more than one are outputted." do
|
@@ -47,7 +47,7 @@ describe 'VarDump' do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
describe "not insert responses" do
|
50
|
-
it "nothing is outputted when the value is not set to
|
50
|
+
it "nothing is outputted when the value is not set to var_dump." do
|
51
51
|
get '/'
|
52
52
|
last_response.body.should eql(DummyBody)
|
53
53
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-var-dump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,33 +9,33 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-08 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: &
|
15
|
+
name: awesome_print
|
16
|
+
requirement: &2158675240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - =
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
22
|
-
type: :
|
21
|
+
version: 1.0.2
|
22
|
+
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2158675240
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement: &
|
26
|
+
name: rake
|
27
|
+
requirement: &2158674720 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 0.9.2.2
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2158674720
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rack
|
38
|
-
requirement: &
|
38
|
+
requirement: &2158674180 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.3.5
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2158674180
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rack-test
|
49
|
-
requirement: &
|
49
|
+
requirement: &2158673640 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.5.3
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2158673640
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &2158673180 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,8 +65,8 @@ dependencies:
|
|
65
65
|
version: 2.7.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
69
|
-
description:
|
68
|
+
version_requirements: *2158673180
|
69
|
+
description: provides a method for debugging like var_dump() of php.
|
70
70
|
email:
|
71
71
|
- bunny.hop.md@gmail.com
|
72
72
|
executables: []
|
@@ -80,9 +80,13 @@ files:
|
|
80
80
|
- LICENSE
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
|
-
- lib/rack/railtie.rb
|
84
83
|
- lib/rack/var_dump.rb
|
84
|
+
- lib/rack/var_dump/awesome_print.rb
|
85
|
+
- lib/rack/var_dump/awesome_print/ext/var_dump.rb
|
86
|
+
- lib/rack/var_dump/awesome_print/ext/var_dump.rb.old
|
87
|
+
- lib/rack/var_dump/kernel.rb
|
85
88
|
- lib/rack/var_dump/object.rb
|
89
|
+
- lib/rack/var_dump/railtie.rb
|
86
90
|
- lib/rack/var_dump/version.rb
|
87
91
|
- lib/rails-var-dump.rb
|
88
92
|
- lib/rails_var_dump.rb
|
@@ -113,7 +117,7 @@ rubyforge_project: rack-var-dump
|
|
113
117
|
rubygems_version: 1.8.10
|
114
118
|
signing_key:
|
115
119
|
specification_version: 3
|
116
|
-
summary:
|
120
|
+
summary: provides a method for debugging like var_dump() of php.
|
117
121
|
test_files:
|
118
122
|
- spec/middleware_spec.rb
|
119
123
|
- spec/object_spec.rb
|
data/lib/rack/railtie.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'rails'
|
2
|
-
require 'rack/var_dump'
|
3
|
-
require 'rack/var_dump/object'
|
4
|
-
require 'rack/var_dump/version'
|
5
|
-
|
6
|
-
module Rack
|
7
|
-
class VarDump
|
8
|
-
include Object
|
9
|
-
end
|
10
|
-
|
11
|
-
class Railtie < Rails::Railtie
|
12
|
-
initializer "rack_var_dump.use_middleware" do |app|
|
13
|
-
app.middleware.use Rack::VarDump if ENV['RAILS_ENV'] == "development"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|