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.
@@ -1,24 +1,24 @@
1
+ require "active_record"
2
+
1
3
  module Footnotes
2
4
  module Notes
3
5
  class AssignsNote < AbstractNote
4
- @@ignored_assigns = [
5
- :@real_format,
6
- :@before_filter_chain_aborted,
7
- :@performed_redirect,
8
- :@performed_render,
9
- :@_params,
10
- :@_response,
11
- :@url,
12
- :@template,
13
- :@_request,
14
- :@db_rt_before_render,
15
- :@db_rt_after_render,
16
- :@view_runtime,
17
- :@marked_for_same_origin_verification
18
- ]
19
- cattr_accessor :ignored_assigns, :instance_writer => false
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
- var_name = var.to_s
44
- rr << ["<strong>#{var.to_s}</strong>" + "<br /><em>#{class_name}</em>", escape(assigned_value(var).inspect)]
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'])
@@ -23,7 +23,7 @@ module Footnotes
23
23
  end
24
24
 
25
25
  def controller_filename
26
- @controller_filename ||= Gem.find_files(controller_path).first # tnx https://github.com/MasterLambaster
26
+ @controller_filename ||= Gem.find_files(controller_path).first
27
27
  end
28
28
 
29
29
  def controller_text
@@ -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
- cattr_accessor :logs
8
- cattr_accessor :original_logger
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
- # Rails 3 don't have ActiveSupport::Logger#broadcast so we backported it
22
- extend_module = defined?(ActiveSupport::Logger) ? ActiveSupport::Logger.broadcast(note_logger) : NoteLogger.broadcast(note_logger)
23
- Rails.logger = self.original_logger.clone.extend(extend_module)
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
- cattr_accessor :partials
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 *args
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
- cattr_accessor :alert_db_time, :alert_sql_number, :orm, :ignored_regexps, :instance_writer => false
5
- @@alert_db_time = 16.0
6
- @@alert_sql_number = 8
7
- @@query_subscriber = nil
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
- cattr_accessor :template
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 *args
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" % self.template[:duration]}ms)"
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 = self.class.template.try(:[], :file)
37
+ @filename = template.try(:[], :file)
38
38
  end
39
39
 
40
40
  end
@@ -1,3 +1,3 @@
1
1
  module Footnotes
2
- VERSION = "7.0.0"
2
+ VERSION = "7.0.1"
3
3
  end
@@ -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
- mattr_accessor :before_hooks
11
- @@before_hooks = []
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
- @@before_hooks << block
39
+ before_hooks << block
41
40
  end
42
41
 
43
42
  def self.after(&block)
44
- @@after_hooks << block
43
+ after_hooks << block
45
44
  end
46
45
 
47
46
  def self.enabled?(controller)
48
- if @@enabled.is_a? Proc
49
- if @@enabled.arity == 1
50
- @@enabled.call(controller)
47
+ if enabled.is_a? Proc
48
+ if enabled.arity == 1
49
+ enabled.call(controller)
51
50
  else
52
- @@enabled.call
51
+ enabled.call
53
52
  end
54
53
  else
55
- !!@@enabled
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 && Rails.root.join('.rails_footnotes').exist?
70
+ load Rails.root.join('.rails_footnotes') if Rails.root&.join('.rails_footnotes')&.exist?
@@ -1,6 +1,4 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "rails-footnotes/version"
1
+ require_relative "./lib/rails-footnotes/version"
4
2
 
5
3
  Gem::Specification.new do |s|
6
4
  s.name = "rails-footnotes"