Module: DeprecationCollector::Web::Helpers
- Defined in:
- lib/deprecation_collector/web/helpers.rb
Overview
:nodoc:
Instance Method Summary collapse
- #collector_instance ⇒ Object
- #current_color_theme ⇒ Object
- #current_path ⇒ Object
- #deprecation_path(id, format: nil) ⇒ Object
- #deprecation_tags(deprecation) ⇒ Object
- #deprecations_path ⇒ Object
- #detect_tag(deprecation) ⇒ Object
- #disable_deprecations_path ⇒ Object
- #dump_deprecations_path ⇒ Object
- #enable_deprecations_path ⇒ Object
- #import_deprecations_path ⇒ Object
- #import_enabled? ⇒ Boolean
- #root_path ⇒ Object
- #test_deprecation?(deprecation) ⇒ Boolean
- #trigger_kwargs_error_warning(foo: nil) ⇒ Object
- #trigger_rails_deprecation ⇒ Object
Instance Method Details
#collector_instance ⇒ Object
7 8 9 |
# File 'lib/deprecation_collector/web/helpers.rb', line 7 def collector_instance @collector_instance || DeprecationCollector.instance end |
#current_color_theme ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/deprecation_collector/web/helpers.rb', line 59 def current_color_theme return "dark" if params["dark"] return "light" if params["light"] return "dark" if request.get_header("HTTP_Sec_CH_Prefers_Color_Scheme").to_s.downcase.include?("dark") "auto" end |
#current_path ⇒ Object
20 21 22 |
# File 'lib/deprecation_collector/web/helpers.rb', line 20 def current_path @current_path ||= request.path_info.gsub(%r{^/}, "") end |
#deprecation_path(id, format: nil) ⇒ Object
28 29 30 |
# File 'lib/deprecation_collector/web/helpers.rb', line 28 def deprecation_path(id, format: nil) ["#{root_path}#{id}", format].compact.join(".") end |
#deprecation_tags(deprecation) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/deprecation_collector/web/helpers.rb', line 81 def (deprecation) = Set.new if (detected_tag = detect_tag(deprecation)) << detected_tag end << :test if test_deprecation?(deprecation) << deprecation[:realm] if deprecation[:realm] && deprecation[:realm] != "rails" .merge(deprecation.dig(:notes, :tags) || []) .map do |tag| if tag == :test [tag, "bg-success"] else [tag, "bg-secondary"] end end.to_h end |
#deprecations_path ⇒ Object
24 25 26 |
# File 'lib/deprecation_collector/web/helpers.rb', line 24 def deprecations_path root_path # / end |
#detect_tag(deprecation) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/deprecation_collector/web/helpers.rb', line 67 def detect_tag(deprecation) msg = deprecation[:message].to_s return :kwargs if msg.include?("Using the last argument as keyword parameters is deprecated") || msg.include?("Passing the keyword argument as the last hash parameter is deprecated") nil end |
#disable_deprecations_path ⇒ Object
36 37 38 |
# File 'lib/deprecation_collector/web/helpers.rb', line 36 def disable_deprecations_path "#{root_path}disable" end |
#dump_deprecations_path ⇒ Object
40 41 42 |
# File 'lib/deprecation_collector/web/helpers.rb', line 40 def dump_deprecations_path "#{root_path}dump.json" end |
#enable_deprecations_path ⇒ Object
32 33 34 |
# File 'lib/deprecation_collector/web/helpers.rb', line 32 def enable_deprecations_path "#{root_path}enable" end |
#import_deprecations_path ⇒ Object
44 45 46 |
# File 'lib/deprecation_collector/web/helpers.rb', line 44 def import_deprecations_path "#{root_path}import" end |
#import_enabled? ⇒ Boolean
11 12 13 |
# File 'lib/deprecation_collector/web/helpers.rb', line 11 def import_enabled? @web.import_enabled end |
#root_path ⇒ Object
15 16 17 18 |
# File 'lib/deprecation_collector/web/helpers.rb', line 15 def root_path # request.base_url ? "#{env['SCRIPT_NAME']}/" end |
#test_deprecation?(deprecation) ⇒ Boolean
75 76 77 78 79 |
# File 'lib/deprecation_collector/web/helpers.rb', line 75 def test_deprecation?(deprecation) %w[trigger_kwargs_error_warning trigger_rails_deprecation].any? do |method| deprecation[:message].to_s.include?(method) end end |
#trigger_kwargs_error_warning(foo: nil) ⇒ Object
48 |
# File 'lib/deprecation_collector/web/helpers.rb', line 48 def trigger_kwargs_error_warning(foo: nil); end |
#trigger_rails_deprecation ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/deprecation_collector/web/helpers.rb', line 50 def trigger_rails_deprecation return unless defined?(ActiveSupport::Deprecation) deprecator = ActiveSupport::Deprecation deprecator = ActiveSupport::Deprecation.new("0.0", "deprecation_collector") if Rails.gem_version >= Gem::Version.new("7.1") -> { deprecator.warn("Test deprecation") } [] end |