rails_info 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +58 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/javascripts/rails_info/application.js +6 -0
  5. data/app/assets/javascripts/rails_info/base.js.coffee +6 -0
  6. data/app/assets/javascripts/rails_info/bootstrap.js.coffee +4 -0
  7. data/app/assets/stylesheets/rails_info/application.css +14 -0
  8. data/app/assets/stylesheets/rails_info/base.css.scss +22 -0
  9. data/app/assets/stylesheets/rails_info/bootstrap_and_overrides.css.less +63 -0
  10. data/app/assets/stylesheets/rails_info/exception.css +17 -0
  11. data/app/assets/stylesheets/rails_info/exception/base.css.scss +31 -0
  12. data/app/assets/stylesheets/rails_info/exception/pygments.css.erb +5 -0
  13. data/app/controllers/rails_info/data_controller.rb +9 -0
  14. data/app/controllers/rails_info/logs/server_controller.rb +10 -0
  15. data/app/controllers/rails_info/logs/test/rspec_controller.rb +16 -0
  16. data/app/controllers/rails_info/model_controller.rb +5 -0
  17. data/app/controllers/rails_info/properties_controller.rb +4 -0
  18. data/app/controllers/rails_info/routes_controller.rb +4 -0
  19. data/app/controllers/rails_info/stack_traces_controller.rb +11 -0
  20. data/app/controllers/rails_info_controller.rb +16 -0
  21. data/app/helpers/rails_info/resources_helper.rb +194 -0
  22. data/app/presenters/rails_info/code_presenter.rb +63 -0
  23. data/app/presenters/rails_info/data/object_presenter.rb +34 -0
  24. data/app/presenters/rails_info/data/row_set_presenter.rb +38 -0
  25. data/app/presenters/rails_info/data_presenter.rb +21 -0
  26. data/app/presenters/rails_info/logs/server/action_presenter.rb +109 -0
  27. data/app/presenters/rails_info/logs/server_presenter.rb +57 -0
  28. data/app/presenters/rails_info/logs/test/rspec/file_presenter.rb +87 -0
  29. data/app/presenters/rails_info/logs/test/rspec_presenter.rb +32 -0
  30. data/app/presenters/rails_info/model_presenter.rb +68 -0
  31. data/app/presenters/rails_info/presenter.rb +19 -0
  32. data/app/presenters/rails_info/stack_trace_presenter.rb +98 -0
  33. data/app/views/layouts/_layout.html.erb +19 -0
  34. data/app/views/layouts/rails_info.html.erb +1 -0
  35. data/app/views/layouts/rails_info/exception.html.erb +1 -0
  36. data/app/views/layouts/shared/_navigation.html.erb +7 -0
  37. data/app/views/rails_info/data/index.html.erb +23 -0
  38. data/app/views/rails_info/logs/server/_table.html.erb +16 -0
  39. data/app/views/rails_info/logs/server/new.html.erb +19 -0
  40. data/app/views/rails_info/logs/test/rspec/new.html.erb +10 -0
  41. data/app/views/rails_info/model/index.html.erb +14 -0
  42. data/app/views/rails_info/properties/index.html.erb +1 -0
  43. data/app/views/rails_info/routes/index.html.erb +18 -0
  44. data/app/views/rails_info/stack_traces/_accordion.html.erb +1 -0
  45. data/app/views/rails_info/stack_traces/_form.html.erb +11 -0
  46. data/app/views/rails_info/stack_traces/_with_request_and_response.html.erb +16 -0
  47. data/app/views/rails_info/stack_traces/new.html.erb +10 -0
  48. data/config/navigation.rb +20 -0
  49. data/config/routes.rb +20 -0
  50. data/lib/rails_info.rb +19 -0
  51. data/lib/rails_info/controller.rb +2 -0
  52. data/lib/rails_info/controller/exception_diagnostics.rb +28 -0
  53. data/lib/rails_info/data.rb +55 -0
  54. data/lib/rails_info/engine.rb +9 -0
  55. data/lib/rails_info/logs.rb +2 -0
  56. data/lib/rails_info/logs/server.rb +230 -0
  57. data/lib/rails_info/logs/test.rb +2 -0
  58. data/lib/rails_info/logs/test/rspec.rb +160 -0
  59. data/lib/rails_info/model.rb +221 -0
  60. data/lib/rails_info/stack_trace.rb +155 -0
  61. data/lib/rails_info/version.rb +3 -0
  62. data/lib/tasks/rails_info_tasks.rake +4 -0
  63. data/spec/dummy/README.rdoc +261 -0
  64. data/spec/dummy/Rakefile +7 -0
  65. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  66. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  67. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  68. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  69. data/spec/dummy/app/models/user.rb +3 -0
  70. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  71. data/spec/dummy/config.ru +4 -0
  72. data/spec/dummy/config/application.rb +59 -0
  73. data/spec/dummy/config/boot.rb +10 -0
  74. data/spec/dummy/config/database.yml +42 -0
  75. data/spec/dummy/config/environment.rb +5 -0
  76. data/spec/dummy/config/environments/development.rb +39 -0
  77. data/spec/dummy/config/environments/production.rb +69 -0
  78. data/spec/dummy/config/environments/test.rb +39 -0
  79. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  80. data/spec/dummy/config/initializers/inflections.rb +15 -0
  81. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  82. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  83. data/spec/dummy/config/initializers/session_store.rb +8 -0
  84. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  85. data/spec/dummy/config/locales/en.yml +5 -0
  86. data/spec/dummy/config/routes.rb +2 -0
  87. data/spec/dummy/log/development.log +4876 -0
  88. data/spec/dummy/public/404.html +26 -0
  89. data/spec/dummy/public/422.html +26 -0
  90. data/spec/dummy/public/500.html +25 -0
  91. data/spec/dummy/public/favicon.ico +0 -0
  92. data/spec/dummy/script/rails +6 -0
  93. metadata +274 -0
@@ -0,0 +1,68 @@
1
+ class RailsInfo::ModelPresenter < ::RailsInfo::Presenter
2
+ def initialize(subject, options = {})
3
+ super(subject, options)
4
+
5
+ @rails_info_model = ::RailsInfo::Model.new
6
+ @list = @rails_info_model.list
7
+ end
8
+
9
+ def count
10
+ @list.keys.length.inspect
11
+ end
12
+
13
+ def list
14
+ if @list.none?
15
+ I18n.t('rails_info.data.index.no_models_found')
16
+ else
17
+ @list.map{|row_set| ::RailsInfo::Data::RowSetPresenter.new(subject, row_set: row_set) }.each do |row_set_presenter|
18
+ yield row_set_presenter
19
+ end
20
+
21
+ ""
22
+ end
23
+ end
24
+
25
+ def hash_tree(hash = nil, options = { parent: '' })
26
+ options.assert_valid_keys(:parent)
27
+
28
+ hash ||= @list
29
+ parent = options[parent].to_s
30
+
31
+ content = ''
32
+
33
+ hash.keys.sort.each do |key|
34
+ value = hash[key]
35
+
36
+ if value.is_a?(Hash) && !value.empty?
37
+ sub_content = hash_tree(value, parent: parent.blank? ? key : parent + "::" + key)
38
+ sub_content = (key + @rails_info_model.associations(key, parent: parent) + " " + sub_content).html_safe
39
+ content += content_tag(:li, sub_content)
40
+ else
41
+ content += content_tag(:li, key + @rails_info_model.associations(key, parent: parent))
42
+ end
43
+ end
44
+
45
+ content_tag(:ul, content.html_safe)
46
+ end
47
+
48
+ def creately
49
+ content_tag :pre, @list.keys.sort.map{|key| creately_for_model(key, @list[key]) }.join('')
50
+ end
51
+
52
+ private
53
+
54
+ def creately_for_model(key, model)
55
+ columns = @rails_info_model.columns_for(key, parent: nil)
56
+ content = "#{key}\n--\n"
57
+
58
+ if columns.any?
59
+ columns.each do |column|
60
+ content += "#{column},INT,FK\n"
61
+ end
62
+ end
63
+
64
+ content += "--\nPRIMARY,id\n"
65
+
66
+ content
67
+ end
68
+ end
@@ -0,0 +1,19 @@
1
+ class RailsInfo::Presenter
2
+ def initialize(subject, options = {})
3
+ @subject = subject
4
+ end
5
+
6
+ def subject=(value)
7
+ @subject = value
8
+ end
9
+
10
+ private
11
+
12
+ def subject
13
+ @subject
14
+ end
15
+
16
+ def method_missing(*args, &block)
17
+ @subject.send(*args, &block)
18
+ end
19
+ end
@@ -0,0 +1,98 @@
1
+ class RailsInfo::StackTracePresenter < ::RailsInfo::Presenter
2
+ def initialize(subject, options = {})
3
+ super(subject, options)
4
+
5
+ options[:stack_trace] ||= {}
6
+
7
+ @stack_trace = ::RailsInfo::StackTrace.new(
8
+ options[:stack_trace][:body], rails_root: options[:stack_trace][:rails_root],
9
+ request: options[:stack_trace][:request], exception: options[:stack_trace][:exception],
10
+ show_all: options[:stack_trace][:show_all], lines_of_code_around: options[:stack_trace][:lines_of_code_around]
11
+ )
12
+ end
13
+
14
+ def header
15
+ html = ''
16
+
17
+ if @stack_trace.exception
18
+ html += content_tag(:h1, h(@stack_trace.title))
19
+ html += content_tag(:pre, @stack_trace.message, class: 'stack_trace_message')
20
+ end
21
+
22
+ html += content_tag(:p, content_tag(:code, "Rails.root: #{rails_root}"))
23
+
24
+ html
25
+ end
26
+
27
+ def accordion
28
+ content_tag :div, class: 'accordions' do
29
+ html = ''
30
+
31
+ @stack_trace.hash.each do |file, code|
32
+ file_without_rails_root = file.dup
33
+
34
+ if file_without_rails_root.match(rails_root)
35
+ file_without_rails_root.gsub!(rails_root, '')
36
+ end
37
+
38
+ highligted_line_number = code[:highlighted_line_numbers].is_a?(Array) ? code[:highlighted_line_numbers].first : code[:highlighted_line_numbers]
39
+ link_to_line_number = link_to file_without_rails_root, "##{file_without_rails_root.parameterize}"
40
+ html += content_tag :h3, raw("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#{file_without_rails_root}")
41
+ code_presenter = ::RailsInfo::CodePresenter.new(@subject, code.merge(highlighted_number_name: file_without_rails_root))
42
+
43
+ height = (((@stack_trace.lines_of_code_around * 2) + 1) * 18).round
44
+
45
+ html += content_tag :div, raw(code_presenter.table), style: "max-height:#{height}px; overflow: auto"
46
+ end
47
+
48
+ raw html
49
+ end
50
+ end
51
+
52
+ def request_tab
53
+ clean_params = request.filtered_parameters.clone
54
+ clean_params.delete("action")
55
+ clean_params.delete("controller")
56
+
57
+ request_dump = clean_params.empty? ? 'None' : clean_params.inspect.gsub(',', ",\n")
58
+
59
+ html = content_tag(:p) do
60
+ content_tag(:strong, 'Parameters:') + content_tag(:pre, h(request_dump))
61
+ end
62
+
63
+ [:session, :env].each do |method|
64
+ html += content_tag(:p) do
65
+ link_to "Show #{method} dump", '#', onclick: "document.getElementById('#{method}_dump').style.display='block'; return false;"
66
+ end
67
+
68
+ html += content_tag(:div, id: "#{method}_dump", style: 'display:none') do
69
+ content = method == :env ? request.env.slice(*request.class::ENV_METHODS) : request.send(method)
70
+ content_tag :pre, debug_hash(content)
71
+ end
72
+ end
73
+
74
+ html
75
+ end
76
+
77
+ def response_tab
78
+ content_tag :p do
79
+ content_tag(:strong, 'Headers:') + content_tag(:pre, h(defined?(@response) ? response.headers.inspect.gsub(',', ",\n") : 'None'))
80
+ end
81
+ end
82
+
83
+ private
84
+
85
+ def rails_root
86
+ if @stack_trace.rails_root
87
+ @stack_trace.rails_root
88
+ elsif defined?(Rails) && Rails.respond_to?(:root)
89
+ Rails.root.to_s
90
+ else
91
+ 'unset'
92
+ end
93
+ end
94
+
95
+ def debug_hash(hash)
96
+ hash.sort_by { |k, v| k.to_s }.map { |k, v| "#{k}: #{v.inspect rescue $!.message}" }.join("\n")
97
+ end
98
+ end
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Rails Info</title>
5
+ <%= stylesheet_link_tag controller.send(:_layout) == 'rails_info' ? 'rails_info/application' : controller.send(:_layout), media: 'all' %>
6
+ <%= javascript_include_tag 'rails_info/application' %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+ <%= render 'layouts/shared/navigation' %>
11
+ <div class='container-fluid'>
12
+ <div class="row-fluid">
13
+ <div class="span12">
14
+ <%= yield %>
15
+ </div>
16
+ </div>
17
+ </div>
18
+ </body>
19
+ </html>
@@ -0,0 +1 @@
1
+ <%= render 'layouts/layout'%>
@@ -0,0 +1 @@
1
+ <%= render 'layouts/layout'%>
@@ -0,0 +1,7 @@
1
+ <div class="navbar">
2
+ <div class="navbar-inner">
3
+ <div class="container">
4
+ <%= render_navigation expand_all: true, renderer: :bootstrap %>
5
+ </div>
6
+ </div>
7
+ </div>
@@ -0,0 +1,23 @@
1
+ <%= form_tag update_multiple_rails_info_data_path, method: :post do %>
2
+ <%= @rails_info_data.actions %>
3
+ <%= @rails_info_data.last_objects do |row_set_presenter| %>
4
+ <h3><%= row_set_presenter.name %></h3>
5
+ <div style="max-height:150px; width:100%; overflow: auto">
6
+ <table class="table table-striped">
7
+ <thead>
8
+ <tr class="<%= cycle("odd", "even") %>">
9
+ <%= row_set_presenter.head %>
10
+ </tr>
11
+ </thead>
12
+ <tbody>
13
+ <% row_set_presenter.objects.each do |object_presenter| %>
14
+ <tr class="<%= cycle("odd", "even") %>">
15
+ <%= object_presenter.row %>
16
+ </tr>
17
+ <% end %>
18
+ </tbody>
19
+ </table>
20
+ </div>
21
+ <% end %>
22
+ <%= @rails_info_data.actions %>
23
+ <% end %>
@@ -0,0 +1,16 @@
1
+ <div style="max-height:400px; width:100%; overflow: auto">
2
+ <table>
3
+ <thead>
4
+ <th><%= raw sub_content['columns'].uniq.join('</th><th>') %></th>
5
+ </thead>
6
+ <tbody>
7
+ <% sub_content['rows'].each do |row| %>
8
+ <tr>
9
+ <% sub_content['columns'].uniq.each do |column| %>
10
+ <td><%= row[column] if row[column] %></td>
11
+ <% end %>
12
+ </tr>
13
+ <% end %>
14
+ </tbody>
15
+ </table>
16
+ </div>
@@ -0,0 +1,19 @@
1
+ <style type="text/css">
2
+ .ui-widget {
3
+ font-size: xx-small;
4
+ }
5
+ </style>
6
+ <% form_tag rails_info_server_log_path do %>
7
+ <%= check_box_tag 'debug' %> debug?
8
+ <p>
9
+ <%= text_field_tag 'log[rails_root]', (params['log']['rails_root'] rescue "#{Rails.root}/log/") %>
10
+ </p>
11
+ <p>
12
+ <%= text_area_tag 'log[body]', (params['log']['body'] rescue nil) %>
13
+ </p>
14
+ <p>
15
+ <%= submit_tag 'submit' %>
16
+ </p>
17
+ <% end %>
18
+ <%= raw @rails_info_log.accordion %>
19
+ <%= raw @rails_info_log.write_tabs %>
@@ -0,0 +1,10 @@
1
+ <%= form_tag rails_info_rspec_log_path, method: 'put' do %>
2
+ <p>
3
+ <%= check_box_tag 'debug' %> debug? &nbsp;&nbsp;
4
+ <%= label_tag 'log[rails_root]', raw('<strong>Rails root:</strong>') %>
5
+ <%= text_field_tag 'log[rails_root]', (params['log']['rails_root'] rescue "#{Rails.root}/"), size: 50 %> &nbsp;&nbsp;
6
+ <%= submit_tag 'submit' %>
7
+ </p>
8
+ <% end %>
9
+ <%= raw @rails_info_log.summary %>
10
+ <%= raw @rails_info_log.accordion %>
@@ -0,0 +1,14 @@
1
+ <div class="tabs">
2
+ <ul>
3
+ <li><a href="#model_hash_tree">Tree</a></li>
4
+ <li><a href="#creately">Create.ly</a></li>
5
+ </ul>
6
+ <div id="model_hash_tree">
7
+ <p><%= @rails_info_model.count %> models.</p>
8
+ <%= @rails_info_model.hash_tree %>
9
+ </div>
10
+ <div id="creately">
11
+ <p><%= @rails_info_model.count %> models.</p>
12
+ <%= @rails_info_model.creately %>
13
+ </div>
14
+ </div>
@@ -0,0 +1 @@
1
+ <%= raw Rails::Info.to_html.gsub('<table>', '<table class="table table-striped">') %>
@@ -0,0 +1,18 @@
1
+ <table class="table table-striped">
2
+ <thead>
3
+ <th>Verb</th>
4
+ <th>Path</th>
5
+ <th>Name</th>
6
+ <th>Requirements</th>
7
+ </thead>
8
+ <tbody>
9
+ <% request.env['action_dispatch.routes'].routes.each do |route| %>
10
+ <tr>
11
+ <td><%= route.verb.source.gsub(/[$^]/, '') %></td>
12
+ <td><%= route.path.respond_to?('spec') ? route.path.spec.to_s : route.path %></td>
13
+ <td><%= route.name %></td>
14
+ <td><%= route.requirements.inspect %></td>
15
+ </tr>
16
+ <% end %>
17
+ </tbody>
18
+ </table>
@@ -0,0 +1 @@
1
+ <%= raw @stack_trace.accordion %>
@@ -0,0 +1,11 @@
1
+ <% if ['new', 'create'].include?(action_name) %>
2
+ <%= form_tag rails_info_stack_trace_path, method: :post do %>
3
+ <% rails_root = params[:stack_trace] && params[:stack_trace][:rails_root].present? ? params[:stack_trace][:rails_root] : Rails.root.to_s %>
4
+ <% body = params[:stack_trace] && params[:stack_trace][:body].present? ? params[:stack_trace][:body] : '' %>
5
+ <% show_all = params[:stack_trace] && params[:stack_trace][:show_all].present? ? params[:stack_trace][:show_all] : false %>
6
+ <p><%= label_tag 'stack_trace[rails_root]', 'Rails Root:' %> <%= text_field_tag 'stack_trace[rails_root]', rails_root, size: 50 %>
7
+ <p><%= check_box_tag 'stack_trace[show_all]', 1, show_all %>
8
+ <p><%= text_area_tag 'stack_trace[body]', body, cols: 100, rows: 5 %>
9
+ <p><%= submit_tag %></p>
10
+ <% end %>
11
+ <% end %>
@@ -0,0 +1,16 @@
1
+ <div class="tabs">
2
+ <ul>
3
+ <li><a href="#stack_trace">Stack trace</a></li>
4
+ <li><a href="#request">Request</a></li>
5
+ <li><a href="#response">Response</a></li>
6
+ </ul>
7
+ <div id="stack_trace">
8
+ <%= render 'rails_info/stack_traces/accordion' %>
9
+ </div>
10
+ <div id="request">
11
+ <%= raw @stack_trace.request_tab %>
12
+ </div>
13
+ <div id="response">
14
+ <%= raw @stack_trace.response_tab %>
15
+ </div>
16
+ </div>
@@ -0,0 +1,10 @@
1
+ <%= render 'rails_info/stack_traces/form' unless @stack_trace %>
2
+ <% if @stack_trace %>
3
+ <%= raw @stack_trace.header %>
4
+
5
+ <% if @stack_trace.request && @stack_trace.response %>
6
+ <%= render 'rails_info/stack_traces/with_request_and_response' %>
7
+ <% else %>
8
+ <%= render 'rails_info/stack_traces/accordion' %>
9
+ <% end %>
10
+ <% end %>
@@ -0,0 +1,20 @@
1
+ SimpleNavigation::Configuration.run do |navigation|
2
+ navigation.items do |primary|
3
+ primary.dom_class = 'nav'
4
+ primary.item :root, 'Index', rails_info_path
5
+ primary.item :properties, 'Properties', rails_info_properties_path
6
+ primary.item :routes, 'Routes', rails_info_routes_path
7
+
8
+ primary.item :model, 'Model', rails_info_model_path do |model|
9
+ model.item :model_index, 'Index', rails_info_model_path
10
+ model.item :data, 'Data', rails_info_data_path
11
+ end
12
+
13
+ primary.item :logs, 'Logs', '#logs' do |logs|
14
+ logs.item :server, 'Server', new_rails_info_server_log_path
15
+ logs.item :rspec, 'Test > RSpec', new_rails_info_rspec_log_path
16
+ end
17
+
18
+ primary.item :stack_traces, 'Stack Traces', new_rails_info_stack_trace_path
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ Rails.application.routes.draw do
2
+ get '/rails/info' => 'rails_info/properties#index', as: 'rails_info'
3
+
4
+ get '/rails/info/properties', to: 'rails_info/properties#index', as: 'rails_info_properties'
5
+ get '/rails/info/routes', to: 'rails_info/routes#index', as: 'rails_info_routes'
6
+
7
+ get '/rails/info/model', to: 'rails_info/model#index', as: 'rails_info_model'
8
+
9
+ get '/rails/info/data', to: 'rails_info/data#index', as: 'rails_info_data', as: 'rails_info_data'
10
+ post '/rails/info/data/update_multiple', to: 'rails_info/data#update_multiple', as: 'update_multiple_rails_info_data'
11
+
12
+ get '/rails/info/logs/server' => 'rails_info/logs/server#new', as: 'new_rails_info_server_log'
13
+ put '/rails/info/logs/server' => 'rails_info/logs/server#update', as: 'rails_info_server_log'
14
+
15
+ get '/rails/info/logs/test/rspec' => 'rails_info/logs/test/rspec#new', as: 'new_rails_info_rspec_log'
16
+ put '/rails/info/logs/test/rspec' => 'rails_info/logs/test/rspec#update', as: 'rails_info_rspec_log'
17
+
18
+ get '/rails/info/stack_traces/new' => 'rails_info/stack_traces#new', as: 'new_rails_info_stack_trace'
19
+ post '/rails/info/stack_traces' => 'rails_info/stack_traces#create', as: 'rails_info_stack_trace'
20
+ end
@@ -0,0 +1,19 @@
1
+ # view
2
+ require 'jquery-rails'
3
+ require 'jquery-ui-rails'
4
+ require 'pygments'
5
+ require 'simple-navigation-bootstrap'
6
+
7
+ require 'rails_info/engine'
8
+ require 'rails_info/controller'
9
+ require 'rails_info/controller/exception_diagnostics'
10
+ require 'rails_info/model'
11
+ require 'rails_info/data'
12
+ require 'rails_info/logs'
13
+ require 'rails_info/logs/server'
14
+ require 'rails_info/logs/test'
15
+ require 'rails_info/logs/test/rspec'
16
+ require 'rails_info/stack_trace'
17
+
18
+ module RailsInfo
19
+ end