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,63 @@
1
+ class RailsInfo::CodePresenter < ::RailsInfo::Presenter
2
+ def initialize(subject, options = {})
3
+ super(subject, options)
4
+
5
+ @code = options[:text]
6
+ @line_number = options[:number]
7
+ @line_numbers = options[:line_numbers]
8
+ @highlighted_line_numbers = options[:highlighted_line_numbers] || []
9
+ @highlighted_line_numbers = @highlighted_line_numbers.is_a?(Array) ? @highlighted_line_numbers : [@highlighted_line_numbers]
10
+ @highlighted_number_name = options[:highlighted_number_name]
11
+ end
12
+
13
+ def table
14
+ outer_html = ''
15
+
16
+ unless @line_numbers.include?(@line_number)
17
+ outer_html = content_tag(:p) do
18
+ content_tag :strong do
19
+ raw(
20
+ "Line number #{@line_number.inspect} is either an empty line or not included (anymore).<br/>" +
21
+ "So highlighting the nearest line."
22
+ )
23
+ end
24
+ end
25
+ end
26
+
27
+ outer_html + content_tag(:table, cellspacing: 0, cellpadding: 0) do
28
+ html, visible_line_number = '', 1
29
+
30
+ @line_numbers.each do |line_number|
31
+ html += content_tag :tr do
32
+ tr_html = ''
33
+
34
+ if @highlighted_line_numbers.include?(visible_line_number)
35
+ #line_number_link = link_to line_number.to_s, "#top", name: @highlighted_number_name.parameterize
36
+ tr_html = content_tag :td, line_number, class: 'hll'
37
+ else
38
+ tr_html = content_tag :td, line_number
39
+ end
40
+
41
+ if line_number == @line_numbers.first
42
+ options = @highlighted_line_numbers ? {hl_lines: @highlighted_line_numbers } : {}
43
+
44
+ # 1) This Ruby wrapped Python code can cause Ruby segmentation faults.
45
+ # If you can abandon syntax highlighting deactivate 1) and use 2) instead
46
+ code = ::Pygments.highlight(@code, lexer: 'ruby', options: options) rescue @code.gsub(/\n/, '<br/>').gsub(' ', '&nbsp;')
47
+
48
+ # 2)
49
+ # code = @code.gsub(/\n/, '<br/>').gsub(' ', '&nbsp;')
50
+
51
+ tr_html += content_tag :td, raw(code), rowspan: @line_numbers.length
52
+ end
53
+
54
+ raw tr_html
55
+ end
56
+
57
+ visible_line_number += 1
58
+ end
59
+
60
+ raw html
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,34 @@
1
+ class RailsInfo::Data::ObjectPresenter < ::RailsInfo::Presenter
2
+ def initialize(subject, options = {})
3
+ super(subject, options)
4
+
5
+ options.assert_valid_keys(:object)
6
+
7
+ @object = options[:object]
8
+ end
9
+
10
+ def row
11
+ content = content_tag :td, class: 'first' do
12
+ check_box_tag "data[]", "#{object[:class].name};#{object['id']}", false, id: "#{object[:class].name.tableize}-#{object['id']}"
13
+ end
14
+
15
+ object[:class].columns.each do |column|
16
+ value = object[column.name]
17
+
18
+ if ['string', 'text'].include?(column.type.to_s)
19
+ text = value.present? && value.length > 20 ? "#{value[0,20]}..." : value
20
+ value = content_tag :span, text, title: value
21
+ end
22
+
23
+ content += content_tag :td, value
24
+ end
25
+
26
+ content
27
+ end
28
+
29
+ private
30
+
31
+ def object
32
+ @object
33
+ end
34
+ end
@@ -0,0 +1,38 @@
1
+ class RailsInfo::Data::RowSetPresenter < ::RailsInfo::Presenter
2
+ def initialize(subject, options = {})
3
+ super(subject, options)
4
+
5
+ options.assert_valid_keys(:row_set)
6
+
7
+ @row_set = options[:row_set]
8
+ end
9
+
10
+ def name
11
+ row_set.first[:class].name.tableize.humanize
12
+ end
13
+
14
+ def head
15
+ title, group_by = nil, ''
16
+ content = content_tag :th, '', class: 'first'
17
+ column_index = 0
18
+
19
+ resource_columns(row_set, group_by).each do |column|
20
+ style = column == group_by ? 'color:red;' : ''
21
+ sub_content = column == group_by || title == nil ? column : link_to(column, uri_with_new_param('group_by_title[' + title + ']', column))
22
+ content += content_tag :th, sub_content, style: style#, class: klass
23
+ column_index += 1
24
+ end
25
+
26
+ content
27
+ end
28
+
29
+ def objects
30
+ @objects ||= row_set.map{|object| ::RailsInfo::Data::ObjectPresenter.new(subject, object: object) }
31
+ end
32
+
33
+ private
34
+
35
+ def row_set
36
+ @row_set
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ class RailsInfo::DataPresenter < ::RailsInfo::Presenter
2
+ def actions
3
+ content_tag :div, submit_tag(I18n.t('rails_info.data.general.delete'), name: 'delete')
4
+ end
5
+
6
+ def last_objects
7
+ return @last_objects if @last_objects
8
+
9
+ @last_objects = ::RailsInfo::Data.new.last_objects
10
+
11
+ if @last_objects.flatten.none?
12
+ I18n.t('rails_info.data.index.no_models_found')
13
+ else
14
+ @last_objects.map{|row_set| ::RailsInfo::Data::RowSetPresenter.new(subject, row_set: row_set) }.each do |row_set_presenter|
15
+ yield row_set_presenter
16
+ end
17
+
18
+ ""
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,109 @@
1
+ class RailsInfo::Logs::Server::ActionPresenter < ::RailsInfo::Presenter
2
+ def initialize(subject, options = {})
3
+ super(subject, options)
4
+
5
+ @name = options[:name]
6
+ @tabs_data = options[:tabs_data]
7
+ @index = options[:index]
8
+ end
9
+
10
+ def tabs
11
+ html = content_tag :h3, link_to(@name, '#')
12
+
13
+ html += content_tag(:div, class: 'tabs', id: "tabs-#{@index}") do
14
+ raw(navigation) + raw(body)
15
+ end
16
+
17
+ html
18
+ end
19
+
20
+ private
21
+
22
+ def navigation
23
+ content_tag :ul do
24
+ @tab_index = 0
25
+
26
+ elements = ''
27
+
28
+ @tabs_data.keys.select{|tab_key| tab_key.present?}.each do |tab_key|
29
+ elements += content_tag :li, link_to(tab_key, "#tabs-#{@index}-#{@tab_index}")
30
+ @tab_index += 1
31
+ end
32
+
33
+ raw elements
34
+ end
35
+ end
36
+
37
+ def body
38
+ @tab_index, html = 0, ''
39
+
40
+ @tabs_data.keys.select{|tab_key| tab_key.present?}.each do |tab_key|
41
+ html += raw tab(tab_key)
42
+ end
43
+
44
+ html
45
+ end
46
+
47
+ def tab(tab_key)
48
+ @content = @tabs_data[tab_key]
49
+
50
+ content_tag :div, class: 'tabs', id: "tabs-#{@index}-#{@tab_index}" do
51
+ raw @content.is_a?(Hash) ? sub_tabs : sub_content_tab
52
+ end
53
+ end
54
+
55
+ def sub_tabs
56
+ html = ''
57
+
58
+ html += content_tag :div, class: 'tabs', id: "tabs-#{@index}-#{@tab_index}-subtabs" do
59
+ raw(sub_navigation) + raw(sub_body)
60
+ end
61
+
62
+ html
63
+ end
64
+
65
+ def sub_content_tab
66
+ content_tag :div, style: 'max-height:400px; width:100%; overflow: auto' do
67
+ if @content.is_a?(Array)
68
+ @content.map!{|c| CGI.escapeHTML(c) }.join('<br/><br/>')
69
+ else
70
+ @content = CGI.escapeHTML(@content)
71
+ end
72
+
73
+ @tab_index += 1
74
+
75
+ raw @content
76
+ end
77
+ end
78
+
79
+ def sub_navigation
80
+ sub_tab_index = 0
81
+
82
+ content_tag :ul do
83
+ elements = ''
84
+
85
+ @content.keys.map(&:to_s).select{|tab_key| tab_key.present? }.each do |tab_key|
86
+ elements += content_tag :li, link_to(tab_key, "#tabs-#{@index}-#{@tab_index}-#{sub_tab_index}")
87
+ sub_tab_index += 1
88
+ end
89
+
90
+ raw elements
91
+ end
92
+ end
93
+
94
+ def sub_body
95
+ html, sub_tab_index = '', 0
96
+
97
+ @content.keys.map(&:to_s).select{|tab| tab.present? }.each do |tab|
98
+ sub_content = @content[tab]
99
+
100
+ html += content_tag :div, class: 'tabs', id: "tabs-#{@index}-#{@tab_index}-#{sub_tab_index}" do
101
+ sub_tab_index += 1
102
+ @tab_index += 1
103
+ raw render partial: 'rails_info/logs/server/table', locals: { sub_content: sub_content }
104
+ end
105
+ end
106
+
107
+ html
108
+ end
109
+ end
@@ -0,0 +1,57 @@
1
+ class RailsInfo::Logs::ServerPresenter < ::RailsInfo::Presenter
2
+ def initialize(subject, options = {})
3
+ super(subject, options)
4
+
5
+ @rails_info_log = ::RailsInfo::Logs::Server.new(log: params[:log], debug: params[:debug])
6
+ end
7
+
8
+ def accordion
9
+ @action_index = 0
10
+
11
+ content_tag :div, id: 'actions', class: 'accordions' do
12
+ html = ''
13
+
14
+ @rails_info_log.hash.each do |action, tabs|
15
+ action_presenter = ::RailsInfo::Logs::Server::ActionPresenter.new(
16
+ @subject, name: action, tabs_data: tabs, index: @action_index
17
+ )
18
+ @action_index += 1
19
+ html += raw action_presenter.tabs
20
+ end
21
+
22
+ raw html
23
+ end
24
+ end
25
+
26
+ def write_tabs
27
+ content_tag :div, class: 'tabs', id: 'writes' do
28
+ write_navigation
29
+ write_body
30
+ end
31
+ end
32
+
33
+ def write_navigation
34
+ tab_index = 0
35
+
36
+ content_tag :ul do
37
+ @rails_info_log.writes.each do |table_name,data|
38
+ li = content_tag :li, link_to(table_name, "writes-#{tab_index}")
39
+
40
+ tab_index += 1
41
+
42
+ li
43
+ end
44
+ end
45
+ end
46
+
47
+ def write_body
48
+ tab_index = 0
49
+
50
+ @rails_info_log.writes.each do |table_name,data|
51
+ content_tag :div, class: 'tabs', id: "writes-#{tab_index}" do
52
+ tab_index += 1
53
+ render partial: 'table', locals: { sub_content: data }
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,87 @@
1
+ class RailsInfo::Logs::Test::Rspec::FilePresenter < ::RailsInfo::Presenter
2
+ def initialize(subject, options = {})
3
+ super(subject, options)
4
+
5
+ @name = options[:name]
6
+ @tabs_data = options[:tabs_data]
7
+ @index = options[:index]
8
+ @rails_root = options[:rails_root]
9
+ end
10
+
11
+ def tabs
12
+ html = content_tag :h3, link_to(@name, '#')
13
+
14
+ html += content_tag(:div, class: 'tabs', id: "#{@name.parameterize}-tabs-#{@index}") do
15
+ raw(navigation) + raw(body)
16
+ end
17
+
18
+ html
19
+ end
20
+
21
+ private
22
+
23
+ def navigation
24
+ content_tag :ul do
25
+ @tab_index = 0
26
+
27
+ elements = ''
28
+
29
+ @tabs_data.keys.select{|tab_key| tab_key.present?}.each do |tab_key|
30
+ elements += content_tag(
31
+ :li, link_to(tab_key, "##{@name.parameterize}-tabs-#{@index}-#{@tab_index}")
32
+ )
33
+ @tab_index += 1
34
+ end
35
+
36
+ raw elements
37
+ end
38
+ end
39
+
40
+ def body
41
+ @tab_index, html = 0, ''
42
+
43
+ @tabs_data.keys.select{|tab_key| tab_key.present?}.each do |tab_key|
44
+ html += raw tab(tab_key)
45
+ end
46
+
47
+ html
48
+ end
49
+
50
+ def tab(tab_key)
51
+ @content = @tabs_data[tab_key]
52
+
53
+ content_tag :div, class: 'tabs', id: "#{@name.parameterize}-tabs-#{@index}-#{@tab_index}" do
54
+ sub_content_tab
55
+ end
56
+ end
57
+
58
+ def sub_content_tab
59
+ content_tag :div, style: 'max-height:300px; overflow: auto' do
60
+ attributes = []
61
+
62
+ [:failure_code, :exception_class].each do |attribute|
63
+ attributes << (content_tag(:strong, "#{attribute.to_s.humanize}: ") + h(@content[attribute]))
64
+ end
65
+
66
+ html = content_tag(:p, raw(attributes.join('&nbsp;&nbsp;|&nbsp;&nbsp;')))
67
+
68
+ html += content_tag(:p) do
69
+ content_tag(:strong, "#{:exception_message.to_s.humanize}: ") +
70
+ content_tag(:div, style: 'max-height:100px; overflow: auto') do
71
+ raw(h(@content[:exception_message]).gsub('\n', '<br/>'))
72
+ end
73
+ end
74
+
75
+ html += RailsInfo::StackTracePresenter.new(
76
+ @subject,
77
+ stack_trace: {
78
+ body: @content[:stack_trace], rails_root: @rails_root, lines_of_code_around: 3
79
+ }
80
+ ).accordion
81
+
82
+ @tab_index += 1
83
+
84
+ raw html
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,32 @@
1
+ class RailsInfo::Logs::Test::RspecPresenter < ::RailsInfo::Presenter
2
+ def initialize(subject, options = {})
3
+ super(subject, options)
4
+
5
+ @rails_info_log = ::RailsInfo::Logs::Test::Rspec.new(
6
+ log: options[:log], debug: options[:debug]
7
+ )
8
+ end
9
+
10
+ def summary
11
+ content_tag :p, "#{@rails_info_log.hash.keys.length} files, #{@rails_info_log.summary}"
12
+ end
13
+
14
+ def accordion
15
+ @index = 0
16
+
17
+ content_tag :div, id: 'files', class: 'accordions' do
18
+ html = ''
19
+
20
+ @rails_info_log.hash.each do |file, examples|
21
+ file_presenter = ::RailsInfo::Logs::Test::Rspec::FilePresenter.new(
22
+ @subject, name: "#{file} (#{examples.length})",
23
+ tabs_data: examples, index: @index, rails_root: @rails_info_log.rails_root
24
+ )
25
+ @index += 1
26
+ html += raw file_presenter.tabs
27
+ end
28
+
29
+ raw html
30
+ end
31
+ end
32
+ end