Module: Olyx::Guardrails::Rails::Upload

Defined in:
lib/olyx/guardrails/rails/upload.rb

Overview

Evaluates caller-extracted upload text.

The application remains responsible for file-size limits, type validation, malware scanning, storage, and bounded text extraction.

Class Method Summary collapse

Class Method Details

.check(upload, extractor:, metadata: {}) ⇒ Object

:call-seq:

Upload.check(upload, extractor:, metadata: {}) -> Hash

Calls extractor with upload and evaluates the returned String. metadata must be a Hash. The extractor must be callable and return a String; otherwise this method raises ArgumentError.



20
21
22
23
24
# File 'lib/olyx/guardrails/rails/upload.rb', line 20

def self.check(upload, extractor:, metadata: {})
  text = extract(upload, extractor)
  Validation.hash!(, name: 'guardrail metadata')
  Guardrails::Rails.check(text, metadata: { ingress: 'upload' }.merge())
end

.check!(upload, extractor:, metadata: {}) ⇒ Object

:call-seq:

Upload.check!(upload, extractor:, metadata: {}) -> Hash

Behaves like check, returning an allowed decision or raising Blocked.



30
31
32
33
34
# File 'lib/olyx/guardrails/rails/upload.rb', line 30

def self.check!(upload, extractor:, metadata: {})
  text = extract(upload, extractor)
  Validation.hash!(, name: 'guardrail metadata')
  Enforcer.check!(text, metadata: { ingress: 'upload' }.merge())
end