rails-footnotes 7.0.0 → 7.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/Gemfile.lock +107 -68
- data/{README.rdoc → README.md} +65 -59
- data/lib/generators/templates/rails_footnotes.rb +3 -0
- data/lib/rails-footnotes/filter.rb +42 -29
- data/lib/rails-footnotes/notes/assigns_note.rb +23 -20
- data/lib/rails-footnotes/notes/controller_note.rb +1 -1
- data/lib/rails-footnotes/notes/log_note/note_logger.rb +0 -38
- data/lib/rails-footnotes/notes/log_note.rb +8 -5
- data/lib/rails-footnotes/notes/partials_note.rb +2 -2
- data/lib/rails-footnotes/notes/queries_note.rb +4 -6
- data/lib/rails-footnotes/notes/view_note.rb +4 -4
- data/lib/rails-footnotes/version.rb +1 -1
- data/lib/rails-footnotes.rb +18 -16
- data/rails-footnotes.gemspec +1 -3
- data/spec/footnotes_spec.rb +173 -140
- data/spec/notes/assigns_note_spec.rb +27 -9
- data/spec/spec_helper.rb +1 -1
- data/spec/support/active_record.rb +22 -0
- metadata +5 -3
@@ -1,24 +1,24 @@
|
|
1
|
+
require "active_record"
|
2
|
+
|
1
3
|
module Footnotes
|
2
4
|
module Notes
|
3
5
|
class AssignsNote < AbstractNote
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@@ignored_assigns_pattern = /^@_/
|
21
|
-
cattr_accessor :ignored_assigns_pattern, :instance_writer => false
|
6
|
+
thread_cattr_accessor :ignored_assigns, instance_writer: false, default: [
|
7
|
+
:@real_format,
|
8
|
+
:@before_filter_chain_aborted,
|
9
|
+
:@performed_redirect,
|
10
|
+
:@performed_render,
|
11
|
+
:@_params,
|
12
|
+
:@_response,
|
13
|
+
:@url,
|
14
|
+
:@template,
|
15
|
+
:@_request,
|
16
|
+
:@db_rt_before_render,
|
17
|
+
:@db_rt_after_render,
|
18
|
+
:@view_runtime,
|
19
|
+
:@marked_for_same_origin_verification
|
20
|
+
]
|
21
|
+
thread_cattr_accessor :ignored_assigns_pattern, instance_writer: false, default: /^@_/
|
22
22
|
|
23
23
|
def initialize(controller)
|
24
24
|
@controller = controller
|
@@ -40,8 +40,11 @@ module Footnotes
|
|
40
40
|
def to_table
|
41
41
|
table = assigns.inject([]) do |rr, var|
|
42
42
|
class_name = assigned_value(var).class.name
|
43
|
-
|
44
|
-
|
43
|
+
var_value = assigned_value(var)
|
44
|
+
if var_value.is_a?(ActiveRecord::Relation) && var_value.limit_value.nil?
|
45
|
+
var_value = var_value.limit(Footnotes::Filter.default_limit)
|
46
|
+
end
|
47
|
+
rr << ["<strong>#{var.to_s}</strong>" + "<br /><em>#{class_name}</em>", escape(var_value.inspect)]
|
45
48
|
end
|
46
49
|
|
47
50
|
table.unshift(['Name', 'Value'])
|
@@ -15,44 +15,6 @@ module Footnotes
|
|
15
15
|
formatter = @formatter || Logger::Formatter.new
|
16
16
|
@logs << formatter.call(format_severity(severity), Time.now, message, progname)
|
17
17
|
end
|
18
|
-
|
19
|
-
## Backport from rails 4 for handling logging broadcast, should be removed when rails 3 is deprecated :
|
20
|
-
|
21
|
-
# Broadcasts logs to multiple loggers.
|
22
|
-
def self.broadcast(logger) # :nodoc:
|
23
|
-
Module.new do
|
24
|
-
define_method(:add) do |*args, &block|
|
25
|
-
logger.add(*args, &block)
|
26
|
-
super(*args, &block)
|
27
|
-
end
|
28
|
-
|
29
|
-
define_method(:<<) do |x|
|
30
|
-
logger << x
|
31
|
-
super(x)
|
32
|
-
end
|
33
|
-
|
34
|
-
define_method(:close) do
|
35
|
-
logger.close
|
36
|
-
super()
|
37
|
-
end
|
38
|
-
|
39
|
-
define_method(:progname=) do |name|
|
40
|
-
logger.progname = name
|
41
|
-
super(name)
|
42
|
-
end
|
43
|
-
|
44
|
-
define_method(:formatter=) do |formatter|
|
45
|
-
logger.formatter = formatter
|
46
|
-
super(formatter)
|
47
|
-
end
|
48
|
-
|
49
|
-
define_method(:level=) do |level|
|
50
|
-
logger.level = level
|
51
|
-
super(level)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
18
|
end
|
57
19
|
end
|
58
20
|
end
|
@@ -4,8 +4,8 @@ module Footnotes
|
|
4
4
|
|
5
5
|
autoload :NoteLogger, 'rails-footnotes/notes/log_note/note_logger'
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
thread_cattr_accessor :logs
|
8
|
+
thread_cattr_accessor :original_logger
|
9
9
|
|
10
10
|
def self.start!(controller)
|
11
11
|
self.logs = []
|
@@ -18,9 +18,12 @@ module Footnotes
|
|
18
18
|
else
|
19
19
|
defined?(ActiveSupport::Logger) ? ActiveSupport::Logger::SimpleFormatter.new : Logger::SimpleFormatter.new
|
20
20
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
|
22
|
+
if ::Rails::VERSION::STRING < "7.1"
|
23
|
+
::Rails.logger.extend(::ActiveSupport::Logger.broadcast(note_logger))
|
24
|
+
else
|
25
|
+
::Rails.logger = ::ActiveSupport::BroadcastLogger.new(::Rails.logger, note_logger)
|
26
|
+
end
|
24
27
|
end
|
25
28
|
|
26
29
|
def title
|
@@ -2,12 +2,12 @@ module Footnotes
|
|
2
2
|
module Notes
|
3
3
|
class PartialsNote < AbstractNote
|
4
4
|
|
5
|
-
|
5
|
+
thread_cattr_accessor :partials
|
6
6
|
|
7
7
|
def self.start!(controller)
|
8
8
|
self.partials = []
|
9
9
|
@subscriber ||= ActiveSupport::Notifications.subscribe('render_partial.action_view') do |*args|
|
10
|
-
event = ActiveSupport::Notifications::Event.new
|
10
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
11
11
|
self.partials << {:file => event.payload[:identifier], :duration => event.duration}
|
12
12
|
end
|
13
13
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module Footnotes
|
2
2
|
module Notes
|
3
3
|
class QueriesNote < AbstractNote
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@@orm = [:active_record, :data_mapper]
|
9
|
-
@@ignored_regexps = [%r{(pg_table|pg_attribute|pg_namespace|show\stables|pragma|sqlite_master)}i]
|
4
|
+
thread_cattr_accessor :alert_db_time, default: 16.0, instance_writer: false
|
5
|
+
thread_cattr_accessor :alert_sql_number, default: 8, instance_writer: false
|
6
|
+
thread_cattr_accessor :orm, default: [:active_record, :data_mapper], instance_writer: false
|
7
|
+
thread_cattr_accessor :ignored_regexps, default: [%r{(pg_table|pg_attribute|pg_namespace|show\stables|pragma|sqlite_master)}i], instance_writer: false
|
10
8
|
|
11
9
|
def self.start!(controller)
|
12
10
|
self.query_subscriber.reset!
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Footnotes
|
2
2
|
module Notes
|
3
3
|
class ViewNote < AbstractNote
|
4
|
-
|
4
|
+
thread_cattr_accessor :template
|
5
5
|
|
6
6
|
def self.start!(controller)
|
7
7
|
@subscriber ||= ActiveSupport::Notifications.subscribe('render_template.action_view') do |*args|
|
8
|
-
event = ActiveSupport::Notifications::Event.new
|
8
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
9
9
|
self.template = {:file => event.payload[:identifier], :duration => event.duration}
|
10
10
|
end
|
11
11
|
end
|
@@ -19,7 +19,7 @@ module Footnotes
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def title
|
22
|
-
"View (#{"%.3f" %
|
22
|
+
"View (#{"%.3f" % template[:duration]}ms)"
|
23
23
|
end
|
24
24
|
|
25
25
|
def link
|
@@ -34,7 +34,7 @@ module Footnotes
|
|
34
34
|
|
35
35
|
def filename
|
36
36
|
return @filename if defined?(@filename)
|
37
|
-
@filename =
|
37
|
+
@filename = template.try(:[], :file)
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
data/lib/rails-footnotes.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rails'
|
2
2
|
require 'action_controller'
|
3
|
+
require 'active_support/core_ext/module/attribute_accessors_per_thread'
|
3
4
|
require 'rails-footnotes/abstract_note'
|
4
5
|
require 'rails-footnotes/each_with_rescue'
|
5
6
|
require 'rails-footnotes/filter'
|
@@ -7,14 +8,9 @@ require 'rails-footnotes/notes/all'
|
|
7
8
|
require 'rails-footnotes/extension'
|
8
9
|
|
9
10
|
module Footnotes
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
mattr_accessor :after_hooks
|
14
|
-
@@after_hooks = []
|
15
|
-
|
16
|
-
mattr_accessor :enabled
|
17
|
-
@@enabled = false
|
11
|
+
thread_mattr_accessor :before_hooks
|
12
|
+
thread_mattr_accessor :after_hooks
|
13
|
+
thread_mattr_accessor :enabled, default: false
|
18
14
|
|
19
15
|
class << self
|
20
16
|
delegate :notes, :to => Filter
|
@@ -34,25 +30,28 @@ module Footnotes
|
|
34
30
|
|
35
31
|
delegate :font_size, :to => Filter
|
36
32
|
delegate :font_size=, :to => Filter
|
33
|
+
|
34
|
+
delegate :default_limit, :to => Filter
|
35
|
+
delegate :default_limit=, :to => Filter
|
37
36
|
end
|
38
37
|
|
39
38
|
def self.before(&block)
|
40
|
-
|
39
|
+
before_hooks << block
|
41
40
|
end
|
42
41
|
|
43
42
|
def self.after(&block)
|
44
|
-
|
43
|
+
after_hooks << block
|
45
44
|
end
|
46
45
|
|
47
46
|
def self.enabled?(controller)
|
48
|
-
if
|
49
|
-
if
|
50
|
-
|
47
|
+
if enabled.is_a? Proc
|
48
|
+
if enabled.arity == 1
|
49
|
+
enabled.call(controller)
|
51
50
|
else
|
52
|
-
|
51
|
+
enabled.call
|
53
52
|
end
|
54
53
|
else
|
55
|
-
|
54
|
+
!!enabled
|
56
55
|
end
|
57
56
|
end
|
58
57
|
|
@@ -61,8 +60,11 @@ module Footnotes
|
|
61
60
|
end
|
62
61
|
end
|
63
62
|
|
63
|
+
Footnotes.before_hooks = []
|
64
|
+
Footnotes.after_hooks = []
|
65
|
+
|
64
66
|
ActiveSupport.on_load(:action_controller) do
|
65
67
|
ActionController::Base.send(:include, Footnotes::RailsFootnotesExtension)
|
66
68
|
end
|
67
69
|
|
68
|
-
load Rails.root.join('.rails_footnotes') if Rails.root
|
70
|
+
load Rails.root.join('.rails_footnotes') if Rails.root&.join('.rails_footnotes')&.exist?
|