Module: SimpleAcp::Models::Types

Defined in:
lib/simple_acp/models/types.rb

Overview

Type definitions, constants, and validations for ACP.

Contains all the enumerated types and validation helpers used throughout the protocol.

Defined Under Namespace

Modules: ContentEncoding, DependencyType, EventType, LinkType, Role, RunMode, RunStatus

Constant Summary collapse

AGENT_NAME_PATTERN =

Agent name must follow RFC 1123 DNS label format

/\A[a-z0-9]([-a-z0-9]*[a-z0-9])?\z/
AGENT_NAME_MAX_LENGTH =

Maximum length for agent names

63

Class Method Summary collapse

Class Method Details

.generate_uuid ⇒ String

Generate a new UUID.

Returns:

  • (String) —

    UUID string



204
205
206
# File 'lib/simple_acp/models/types.rb', line 204

def generate_uuid
  SecureRandom.uuid
end

.valid_agent_name?(name) ⇒ Boolean

Validate an agent name.

Parameters:

  • name (String, nil) —

    name to validate

Returns:

  • (Boolean) —

    true if valid RFC 1123 DNS label



171
172
173
174
175
176
# File 'lib/simple_acp/models/types.rb', line 171

def valid_agent_name?(name)
  return false if name.nil? || name.empty?
  return false if name.length > AGENT_NAME_MAX_LENGTH

  AGENT_NAME_PATTERN.match?(name)
end

.valid_url?(value) ⇒ Boolean

Validate a URL.

Parameters:

  • value (String, nil) —

    value to validate

Returns:

  • (Boolean) —

    true if valid HTTP/HTTPS URL



192
193
194
195
196
197
198
199
# File 'lib/simple_acp/models/types.rb', line 192

def valid_url?(value)
  return false if value.nil?

  uri = URI.parse(value.to_s)
  uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
rescue URI::InvalidURIError
  false
end

.valid_uuid?(value) ⇒ Boolean

Validate a UUID.

Parameters:

  • value (String, nil) —

    value to validate

Returns:

  • (Boolean) —

    true if valid UUID format



182
183
184
185
186
# File 'lib/simple_acp/models/types.rb', line 182

def valid_uuid?(value)
  return false if value.nil?

  /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i.match?(value.to_s)
end