Class: Protege::Gateway::AttachmentPolicy
- Inherits:
-
Data
- Object
- Data
- Protege::Gateway::AttachmentPolicy
- Defined in:
- lib/protege/gateway/attachment_policy.rb
Overview
Immutable attachment limits + the policy that enforces them. A Gateway value type consulted at the
mail edges — built through the Gateway.build_attachment_policy factory and assigned as
config.attachment_policy:
config. = Protege::Gateway.(max_bytes: 5.megabytes)
A Data value with the engine's default limits, consulted at the edges: the inbound mailbox
bounces a violation, and the send_email tool refuses one. enabled is the master switch — when
false, any attachment is rejected (inbound mail with attachments bounces; the agent can't attach
files), while plain mail is unaffected. When enabled, limits are checked in a fixed order — count,
then per-attachment size, then total size — and the first breach wins, so #violation returns a
single human-readable reason (or nil when the set is acceptable).
Instance Attribute Summary collapse
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#max_bytes ⇒ Object
readonly
Returns the value of attribute max_bytes.
-
#max_count ⇒ Object
readonly
Returns the value of attribute max_count.
-
#max_total_bytes ⇒ Object
readonly
Returns the value of attribute max_total_bytes.
Instance Method Summary collapse
-
#initialize(enabled: true, max_count: 10, max_bytes: 10 * 1024 * 1024, max_total_bytes: 25 * 1024 * 1024) ⇒ AttachmentPolicy
constructor
A new instance of AttachmentPolicy.
-
#permits?(byte_sizes:) ⇒ Boolean
Report whether the given attachment sizes are acceptable.
-
#violation(byte_sizes:) ⇒ String?
Return the first reason the set is rejected, or
nilwhen acceptable.
Constructor Details
#initialize(enabled: true, max_count: 10, max_bytes: 10 * 1024 * 1024, max_total_bytes: 25 * 1024 * 1024) ⇒ AttachmentPolicy
Returns a new instance of AttachmentPolicy.
22 23 24 25 26 27 28 29 |
# File 'lib/protege/gateway/attachment_policy.rb', line 22 def initialize( enabled: true, max_count: 10, max_bytes: 10 * 1024 * 1024, max_total_bytes: 25 * 1024 * 1024 ) super end |
Instance Attribute Details
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled
17 18 19 |
# File 'lib/protege/gateway/attachment_policy.rb', line 17 def enabled @enabled end |
#max_bytes ⇒ Object (readonly)
Returns the value of attribute max_bytes
17 18 19 |
# File 'lib/protege/gateway/attachment_policy.rb', line 17 def max_bytes @max_bytes end |
#max_count ⇒ Object (readonly)
Returns the value of attribute max_count
17 18 19 |
# File 'lib/protege/gateway/attachment_policy.rb', line 17 def max_count @max_count end |
#max_total_bytes ⇒ Object (readonly)
Returns the value of attribute max_total_bytes
17 18 19 |
# File 'lib/protege/gateway/attachment_policy.rb', line 17 def max_total_bytes @max_total_bytes end |
Instance Method Details
#permits?(byte_sizes:) ⇒ Boolean
Report whether the given attachment sizes are acceptable.
35 36 37 |
# File 'lib/protege/gateway/attachment_policy.rb', line 35 def permits?(byte_sizes:) violation(byte_sizes:).nil? end |
#violation(byte_sizes:) ⇒ String?
Return the first reason the set is rejected, or nil when acceptable. A message with no
attachments is always acceptable, even when attachments are disabled.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/protege/gateway/attachment_policy.rb', line 44 def violation(byte_sizes:) sizes = Array(byte_sizes) return nil if sizes.empty? %i[ attachments_disabled? too_many_attachments? any_attachment_too_large? total_size_exceeded? ].each do |validator| if (reason = send(validator, sizes)) return reason end end nil end |