Class: Browsable::PolicyScanner

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

Overview

Scans every controller and controller-concern for ‘allow_browser` callsites, so the report can show the full policy landscape — not just the one on ApplicationController that drives the audit target.

This is deliberately *discovery only*. browsable does not try to map each frontend asset to the endpoints (and therefore policies) that serve it: CSS and importmap JavaScript are global assets, pulled in by layout helpers on essentially every page, so they have no single owning controller action. The scanner surfaces the policies; the user decides what to audit against.

Defined Under Namespace

Classes: Policy

Constant Summary collapse

CONTROLLER_GLOB =
"app/controllers/**/*.rb"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ PolicyScanner

Returns a new instance of PolicyScanner.



30
31
32
33
# File 'lib/browsable/policy_scanner.rb', line 30

def initialize(root)
  @root = File.expand_path(root)
  @detector = PolicyDetector.new(@root)
end

Class Method Details

.call(root) ⇒ Object



28
# File 'lib/browsable/policy_scanner.rb', line 28

def self.call(root) = new(root).call

Instance Method Details

#callObject

> Array<Policy>, in a stable (path-sorted) order.



36
37
38
39
40
# File 'lib/browsable/policy_scanner.rb', line 36

def call
  Dir.glob(File.join(@root, CONTROLLER_GLOB)).sort.flat_map { |file| scan_file(file) }
rescue StandardError
  []
end