Class: Tracecontroller

Inherits:
Object
  • Object
show all
Defined in:
lib/tracecontroller.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

VERSION =
Gem.loaded_specs['tracecontroller'].version.to_s

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Tracecontroller

Returns a new instance of Tracecontroller.



11
12
13
# File 'lib/tracecontroller.rb', line 11

def initialize(app)
  @app = app
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



3
4
5
# File 'lib/tracecontroller.rb', line 3

def errors
  @errors
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tracecontroller.rb', line 15

def valid?
  if @errors
    return @errors[:callback].blank? && @errors[:superclass].blank?
  end

  @app.eager_load!
  @app.reload_routes!

  routes = collect_routes(Rails.application.routes.routes).reject {|r| r.requirements[:controller].to_s.blank? }

  @errors = controllers(routes).each.with_object({callback: [], superclass: []}) do |row, errors|
    rules.each do |rule|
      if !rule[:path].match?(row[:path]) || rule[:ignore_classes].any? {|r| r.match? row[:controller_name] }
        next
      end

      if rule[:superclass].present? && row[:superclass_name] != rule[:superclass]
        errors[:superclass] << row[:controller_name]
      end

      callbacks = rule[:require_actions] - row[:callbacks]

      if callbacks.present?
        errors[:callback] << {controller_name: row[:controller_name], callbacks: callbacks}
      end
    end
  end

  @errors[:callback].blank? && @errors[:superclass].blank?
end