rack-var-dump 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rack-var-dump.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Daichi Hirata
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,124 @@
1
+ (書きかけ)
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
+ = Japanese
67
+
68
+ rack-var-dumpはphpのvar_dump()のようなデバッグ用のメソッドを提供します
69
+
70
+ Object Classにvar_dumpメソッドを提供し、レスポンスを返すまでにModel,Controller,View,
71
+
72
+ その他で実行されたすべてのレシーバーもしくは与えた引数をviewに自動的に出力します
73
+
74
+ var_dumpの返り値は常にselfです
75
+
76
+ == Supported versions
77
+
78
+ * Ruby 1.8.7, 1.9.x
79
+
80
+ * Rackを利用しているアプリケーション全般 (rails, sinatra, padrino, etc...)
81
+
82
+ == Install
83
+
84
+ $ gem install rack-var-dump
85
+
86
+ === Rails
87
+
88
+ Gemfileに追加
89
+ gem 'rack-var-dump'
90
+
91
+ Bundle Install
92
+ % bundle install
93
+
94
+ === Rails3.x以上の場合
95
+
96
+ config/application.rb等でRails用に用意されている
97
+ require 'rails-var-dump'
98
+ をrequire
99
+
100
+ === その他Rackアプリケーション
101
+
102
+ rack/var_dumpをrequire
103
+ require 'rack/var_dump'
104
+
105
+ Rack::VarDumpミドルウェアをuse
106
+ use Rack::VarDump
107
+
108
+ == 使い方
109
+
110
+ rails-var-dumpもしくはrack/var_dumpをrequireしている場合、全てのオブジェクトに
111
+ var_dump(var = nil)
112
+ が提供されています
113
+
114
+ === 例
115
+ @users = User.all.var_dump
116
+ var_dump(@users)
117
+
118
+ var_dumpの返り値は常にselfのため、チェーンが途切れずに使用できます
119
+ @first_name = User.find(3).var_dump.first_name
120
+
121
+
122
+ == Copyright
123
+
124
+ Copyright (c) 2012 Daichi Hirata. See LICENSE for details.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,54 @@
1
+ require "rack/utils"
2
+ require "rack/var_dump/object"
3
+ require "rack/var_dump/version"
4
+
5
+ module Rack
6
+ class VarDump
7
+ include Object
8
+
9
+ @@var_aggregates = []
10
+
11
+ def self.var_dump(var)
12
+ @@var_aggregates << var.to_yaml
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
21
+ end
22
+
23
+ def self.reset!
24
+ @@var_aggregates = []
25
+ end
26
+
27
+ def initialize(app)
28
+ @app = app
29
+ end
30
+
31
+ def call(env)
32
+ request = Rack::Request.new(env)
33
+ status, headers, response = @app.call(env)
34
+
35
+ if /^text\/html/ =~ headers["Content-Type"] && !@@var_aggregates.empty?
36
+ body = ""
37
+ response.each {|org_body| body << org_body}
38
+ response = [apply(request, body)] if body =~ /<body.*>/
39
+ headers["Content-Length"] = response.join.bytesize.to_s
40
+ end
41
+ VarDump.reset!
42
+ [status, headers, response]
43
+ end
44
+
45
+ private
46
+ def apply(request, response)
47
+ html = %Q(<div id="var_dump" style="display:block">)
48
+ html << %Q(<pre style="background-color:#eee;padding:10px;font-size:11px;white-space:pre-wrap;">)
49
+ html << Rack::Utils.escape_html(@@var_aggregates.join)
50
+ html << %Q(</pre></div>)
51
+ response.sub(/<body.*>/, '\&' + html)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,17 @@
1
+ module Rack
2
+ class VarDump
3
+ module Object
4
+ def self.included(obj)
5
+ ::Object.send(:include, Method)
6
+ ::Object.extend(Method)
7
+ end
8
+ end
9
+
10
+ module Method
11
+ def var_dump(var = nil)
12
+ Rack::VarDump.var_dump(var || self)
13
+ self
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class VarDump
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'rack/railtie' if defined?(Rails)
@@ -0,0 +1 @@
1
+ require 'rack/railtie' if defined?(Rails)
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rack/var_dump/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rack-var-dump"
7
+ s.version = Rack::VarDump::VERSION
8
+ s.authors = ["Dach_h"]
9
+ s.email = ["bunny.hop.md@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{rack-var-dump provides a method for debugging like var_dump() of php.}
12
+ s.description = s.summary
13
+ s.rubyforge_project = "rack-var-dump"
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ # specify any dependencies here; for example:
20
+ # s.add_development_dependency "rspec"
21
+ # s.add_runtime_dependency "rest-client"
22
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-var-dump
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dach_h
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-26 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: rack-var-dump provides a method for debugging like var_dump() of php.
15
+ email:
16
+ - bunny.hop.md@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.rdoc
25
+ - Rakefile
26
+ - lib/rack/railtie.rb
27
+ - lib/rack/var_dump.rb
28
+ - lib/rack/var_dump/object.rb
29
+ - lib/rack/var_dump/version.rb
30
+ - lib/rails-var-dump.rb
31
+ - lib/rails_var_dump.rb
32
+ - rack-var-dump.gemspec
33
+ homepage: ''
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project: rack-var-dump
53
+ rubygems_version: 1.8.10
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: rack-var-dump provides a method for debugging like var_dump() of php.
57
+ test_files: []
58
+ has_rdoc: