Module: Parse::Agent::Prompts::Validators
- Defined in:
- lib/parse/agent/prompts.rb
Overview
Validators (verbatim from Parse::Agent::MCPServer private methods)
Constant Summary collapse
- IDENTIFIER_RE =
Parse identifier shape (matches Parse class & field names).
/\A[A-Za-z_][A-Za-z0-9_]{0,127}\z/.freeze
- OBJECT_ID_RE =
Parse objectId shape — alphanumeric, typically 10-32 chars.
/\A[A-Za-z0-9]{1,32}\z/.freeze
Class Method Summary collapse
-
.validate_identifier!(value, name) ⇒ String
The validated value.
-
.validate_iso8601!(value, name, required: true) ⇒ String?
The normalised ISO8601 string, or nil when not required and absent.
-
.validate_object_id!(value, name) ⇒ String
The validated value.
Class Method Details
.validate_identifier!(value, name) ⇒ String
Returns the validated value.
49 50 51 52 53 54 |
# File 'lib/parse/agent/prompts.rb', line 49 def self.validate_identifier!(value, name) raise Parse::Agent::ValidationError, "missing required argument: #{name}" if value.nil? || value.to_s.empty? s = value.to_s return s if s.match?(IDENTIFIER_RE) raise Parse::Agent::ValidationError, "#{name} must match #{IDENTIFIER_RE.source} (got: #{s.inspect})" end |
.validate_iso8601!(value, name, required: true) ⇒ String?
Returns the normalised ISO8601 string, or nil when not required and absent.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/parse/agent/prompts.rb', line 67 def self.validate_iso8601!(value, name, required: true) if value.nil? || value.to_s.empty? return nil unless required raise Parse::Agent::ValidationError, "missing required argument: #{name}" end require "time" Time.iso8601(value.to_s).utc.iso8601(3) rescue ArgumentError raise Parse::Agent::ValidationError, "#{name} must be a valid ISO8601 timestamp (got: #{value.inspect})" end |
.validate_object_id!(value, name) ⇒ String
Returns the validated value.
58 59 60 61 62 63 |
# File 'lib/parse/agent/prompts.rb', line 58 def self.validate_object_id!(value, name) raise Parse::Agent::ValidationError, "missing required argument: #{name}" if value.nil? || value.to_s.empty? s = value.to_s return s if s.match?(OBJECT_ID_RE) raise Parse::Agent::ValidationError, "#{name} must be an alphanumeric objectId (got: #{s.inspect})" end |