Class: RosettAi::Policy::OptOutScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/policy/opt_out_scanner.rb

Overview

Scans files for AI-MODIFICATION opt-out markers.

Files containing +# AI-MODIFICATION: disabled+ are added to the protected files list during compilation.

Constant Summary collapse

MARKER =
'AI-MODIFICATION: disabled'

Instance Method Summary collapse

Instance Method Details

#opted_out?(path) ⇒ Boolean

Scans a single file for opt-out markers.

Parameters:

  • path (String)

    absolute or relative file path

Returns:

  • (Boolean)

    true if the file contains an opt-out marker



19
20
21
22
23
24
25
26
# File 'lib/rosett_ai/policy/opt_out_scanner.rb', line 19

def opted_out?(path)
  return false unless File.exist?(path)
  return false unless File.readable?(path)

  File.foreach(path).any? { |line| line.include?(MARKER) }
rescue StandardError
  false
end

#scan(paths) ⇒ Array<String>

Scans multiple files and returns those with opt-out markers.

Parameters:

  • paths (Array<String>)

    file paths to scan

Returns:

  • (Array<String>)

    paths that contain opt-out markers



32
33
34
# File 'lib/rosett_ai/policy/opt_out_scanner.rb', line 32

def scan(paths)
  paths.select { |path| opted_out?(path) }
end