Module: PCP::Protocol

Defined in:
lib/pcp/protocol.rb

Overview

Definitions of RSchema schemas for protocol definitions

Constant Summary collapse

ISO8601 =

A [String] that represents a time according to ISO8601

RSchema.schema do
  predicate do |t|
    begin
      t.is_a?(String) && Time.parse(t)
    rescue ArgumentError
      # Time.parse raises an ArgumentError if the time isn't parsable
      false
    end
  end
end
MessageId =

A [String] that is a message id

RSchema.schema do
  predicate do |id|
    id.is_a?(String) && id.match(%r{^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$})
  end
end
Uri =

A [String] that is a PCP uri

RSchema.schema do
  predicate do |uri|
    uri.is_a?(String) && uri.match(%r{^pcp://([^/]*)/[^/]+$})
  end
end
Envelope =

A [Hash] that complies to the properties of an Envelope

RSchema.schema do
  {
    :id => MessageId,
    optional(:'in-reply-to') => MessageId,
    :sender => Uri,
    :targets => [Uri],
    :message_type => String,
    :expires => ISO8601,
    optional(:destination_report) => boolean,
  }
end