maiha-merb_inspector 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'merb-core'
5
5
  require 'merb-core/tasks/merb'
6
6
 
7
7
  GEM_NAME = "merb_inspector"
8
- GEM_VERSION = "0.2.4"
8
+ GEM_VERSION = "0.2.5"
9
9
  AUTHOR = "Maiha"
10
10
  EMAIL = "maiha@wota.jp"
11
11
  HOMEPAGE = "http://github.com/maiha/merb_inspector"
@@ -0,0 +1,3 @@
1
+ class BasicInspector < Merb::Inspector
2
+ model Merb::Request, StringIO, IO, String, Symbol, Numeric, Class
3
+ end
@@ -0,0 +1,10 @@
1
+ class ObjectInspector < Merb::Inspector
2
+ private
3
+ def template
4
+ if instance_variables.empty?
5
+ :plain
6
+ else
7
+ :default
8
+ end
9
+ end
10
+ end
@@ -2,13 +2,18 @@ module Merb
2
2
  class Inspector
3
3
  module Helper
4
4
  def inspect(object = nil, options = {})
5
- return super() unless object
5
+ return h(super()) unless object
6
6
 
7
7
  options = options.is_a?(Hash) ? options : {:action=>options}
8
- options[:action] ||= :show
9
- options[:level] ||= 1
10
- inspector = (Manager.lookup(object) || Merb::Inspector.default).new(Merb::Request.new({}))
8
+ options[:action] ||= :show
9
+ options[:level] ||= 1
10
+ options[:max_level] ||= 3
11
11
 
12
+ inspector_class = BasicInspector if object == self
13
+ inspector_class = BasicInspector if options[:level] >= options[:max_level]
14
+ inspector_class ||= Manager.lookup(object) || Merb::Inspector.default
15
+
16
+ inspector = inspector_class.new(Merb::Request.new({}))
12
17
  if inspector.respond_to?(options[:action])
13
18
  inspector.send options[:action], object, options
14
19
  else
@@ -13,14 +13,16 @@ module Merb
13
13
  end
14
14
 
15
15
  def self.default
16
- Inspector
16
+ ObjectInspector
17
17
  end
18
18
 
19
19
  ######################################################################
20
20
  ### for class
21
21
 
22
- def self.model(model, inspector = self)
23
- Merb::Inspector::Manager.register(model, inspector)
22
+ def self.model(*models)
23
+ models.each do |model|
24
+ Merb::Inspector::Manager.register(model, self)
25
+ end
24
26
  end
25
27
 
26
28
  def self.lead(options = {})
@@ -113,7 +115,7 @@ module Merb
113
115
  end
114
116
 
115
117
  def child_options
116
- {:level=>@options[:level]+1}
118
+ {:level=>@options[:level]+1, :max_level=>@options[:max_level]}
117
119
  end
118
120
 
119
121
  def wrapped_main
@@ -13,7 +13,8 @@ module Merb
13
13
  self.stores = Hash.new
14
14
  self.caches = Hash.new
15
15
 
16
- File.unlink Merb.root / "log" / "inspector.log"
16
+ log = Merb.root / "log" / "inspector.log"
17
+ File.unlink log if File.exist?(log)
17
18
  load_builtin_inspectors
18
19
  end
19
20
 
@@ -22,8 +23,8 @@ module Merb
22
23
  Dir["#{inspector_dir}/*.rb"].sort.each do |file|
23
24
  begin
24
25
  require file
25
- rescue Exeption => error
26
- message = "[MerbInspector] load error: #{error} (#{error.class})"
26
+ rescue Exception => error
27
+ message = "[MerbInspector] load error: #{error} (#{error.class})\n#{error.backtraces.first rescue nil}"
27
28
  Merb.logger.error message
28
29
  end
29
30
  end
@@ -0,0 +1 @@
1
+ <span class=nowrap><%=h @object.inspect.truncate(80) %></span>
@@ -0,0 +1,19 @@
1
+ <table class="inspector">
2
+ <tr>
3
+ <th><p>key</p></th>
4
+ <th><p>value</p></th>
5
+ <th><p>type</p></th>
6
+ </tr>
7
+ <%- @object.instance_variables.sort.each_with_index do |key, i| -%>
8
+ <%- obj = @object.instance_variable_get(key) -%>
9
+ <%-
10
+ tr_class = (i % 2 == 0) ? "even-record" : ""
11
+ tr_class += " #{list_row_class(obj)}" if respond_to? :list_row_class
12
+ -%>
13
+ <tr class="record <%=tr_class%>">
14
+ <td><%=h key %></td>
15
+ <td><%#h obj.inspect %><%= inspect obj, child_options rescue "error" %></td>
16
+ <td><%=h obj.class.name %></td>
17
+ </tr>
18
+ <%- end -%>
19
+ </table>
@@ -0,0 +1 @@
1
+ <%=h @object.inspect %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maiha-merb_inspector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maiha
@@ -44,14 +44,21 @@ files:
44
44
  - lib/merb_inspector.rb
45
45
  - spec/spec_helper.rb
46
46
  - spec/merb_inspector_spec.rb
47
+ - inspectors/object.rb
47
48
  - inspectors/hash.rb
49
+ - inspectors/basic.rb
48
50
  - inspectors/data_mapper.rb
49
51
  - inspectors/array.rb
50
52
  - templates/hash
51
53
  - templates/hash/_default.html.erb
52
54
  - templates/_default.html.erb
55
+ - templates/basic
56
+ - templates/basic/_default.html.erb
53
57
  - templates/array
54
58
  - templates/array/_default.html.erb
59
+ - templates/object
60
+ - templates/object/_plain.html.erb
61
+ - templates/object/_default.html.erb
55
62
  - templates/data_mapper
56
63
  - templates/data_mapper/resource
57
64
  - templates/data_mapper/resource/_record.html.erb