Class: Coarnotify::Core::Notify::NotifyPattern
- Inherits:
-
NotifyBase
- Object
- NotifyBase
- Coarnotify::Core::Notify::NotifyPattern
- Defined in:
- lib/coarnotify/core/notify.rb
Overview
Base class for all notification patterns
Direct Known Subclasses
Patterns::Accept, Patterns::AnnounceEndorsement, Patterns::AnnounceRelationship, Patterns::AnnounceReview, Patterns::AnnounceServiceResult, Patterns::Reject, Patterns::RequestEndorsement, Patterns::RequestReview, Patterns::TentativelyAccept, Patterns::TentativelyReject, Patterns::UndoOffer, Patterns::UnprocessableNotification
Instance Attribute Summary
Attributes inherited from NotifyBase
#properties_by_reference, #validate_properties, #validate_stream_on_construct, #validators
Class Method Summary collapse
-
.type_constant ⇒ Object
The type of the pattern.
Instance Method Summary collapse
-
#actor ⇒ NotifyActor?
Get the actor property of the notification.
-
#actor=(value) ⇒ Object
Set the actor property of the notification.
-
#context ⇒ NotifyObject?
Get the context property of the notification.
-
#context=(value) ⇒ Object
Set the context property of the notification.
-
#ensure_type_contains(types) ⇒ Object
Ensure that the type field contains the given types.
-
#in_reply_to ⇒ String
Get the inReplyTo property of the notification.
-
#in_reply_to=(value) ⇒ Object
Set the inReplyTo property of the notification.
-
#initialize(stream: nil, validate_stream_on_construct: true, validate_properties: true, validators: nil, validation_context: nil, properties_by_reference: true) ⇒ NotifyPattern
constructor
Constructor for the NotifyPattern.
-
#object ⇒ NotifyObject?
Get the object property of the notification.
-
#object=(value) ⇒ Object
Set the object property of the notification.
-
#origin ⇒ NotifyService?
Get the origin property of the notification.
-
#origin=(value) ⇒ Object
Set the origin property of the notification.
-
#target ⇒ NotifyService?
Get the target property of the notification.
-
#target=(value) ⇒ Object
Set the target property of the notification.
-
#validate ⇒ Boolean
Base validator for all notification patterns.
Methods inherited from NotifyBase
#doc, #get_property, #id, #id=, #optional_and_validate, #register_property_validation_error, #required, #required_and_validate, #set_property, #to_jsonld, #type, #type=, #validate_property
Constructor Details
#initialize(stream: nil, validate_stream_on_construct: true, validate_properties: true, validators: nil, validation_context: nil, properties_by_reference: true) ⇒ NotifyPattern
Constructor for the NotifyPattern
This constructor will ensure that the pattern has its mandated type in the type property
367 368 369 370 371 372 373 |
# File 'lib/coarnotify/core/notify.rb', line 367 def initialize(stream: nil, validate_stream_on_construct: true, validate_properties: true, validators: nil, validation_context: nil, properties_by_reference: true) super(stream: stream, validate_stream_on_construct: validate_stream_on_construct, validate_properties: validate_properties, validators: validators, validation_context: validation_context, properties_by_reference: properties_by_reference) ensure_type_contains(self.class.type_constant) end |
Class Method Details
.type_constant ⇒ Object
The type of the pattern. This should be overridden by subclasses, otherwise defaults to Object
353 354 355 |
# File 'lib/coarnotify/core/notify.rb', line 353 def self.type_constant ActivityStreams2::ActivityStreamsTypes::OBJECT end |
Instance Method Details
#actor ⇒ NotifyActor?
Get the actor property of the notification
470 471 472 473 474 475 476 477 478 |
# File 'lib/coarnotify/core/notify.rb', line 470 def actor a = get_property(ActivityStreams2::Properties::ACTOR) if a NotifyActor.new(stream: a, validate_stream_on_construct: false, validate_properties: @validate_properties, validators: @validators, validation_context: ActivityStreams2::Properties::ACTOR, properties_by_reference: @properties_by_reference) end end |
#actor=(value) ⇒ Object
Set the actor property of the notification
483 484 485 |
# File 'lib/coarnotify/core/notify.rb', line 483 def actor=(value) set_property(ActivityStreams2::Properties::ACTOR, value.doc) end |
#context ⇒ NotifyObject?
Get the context property of the notification
490 491 492 493 494 495 496 497 498 |
# File 'lib/coarnotify/core/notify.rb', line 490 def context c = get_property(ActivityStreams2::Properties::CONTEXT) if c NotifyObject.new(stream: c, validate_stream_on_construct: false, validate_properties: @validate_properties, validators: @validators, validation_context: ActivityStreams2::Properties::CONTEXT, properties_by_reference: @properties_by_reference) end end |
#context=(value) ⇒ Object
Set the context property of the notification
503 504 505 |
# File 'lib/coarnotify/core/notify.rb', line 503 def context=(value) set_property(ActivityStreams2::Properties::CONTEXT, value.doc) end |
#ensure_type_contains(types) ⇒ Object
Ensure that the type field contains the given types
378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/coarnotify/core/notify.rb', line 378 def ensure_type_contains(types) existing = @stream.get_property(ActivityStreams2::Properties::TYPE) if existing.nil? set_property(ActivityStreams2::Properties::TYPE, types) else existing = [existing] unless existing.is_a?(Array) types = [types] unless types.is_a?(Array) types.each do |t| existing << t unless existing.include?(t) end existing = existing.length == 1 ? existing[0] : existing set_property(ActivityStreams2::Properties::TYPE, existing) end end |
#in_reply_to ⇒ String
Get the inReplyTo property of the notification
456 457 458 |
# File 'lib/coarnotify/core/notify.rb', line 456 def in_reply_to get_property(ActivityStreams2::Properties::IN_REPLY_TO) end |
#in_reply_to=(value) ⇒ Object
Set the inReplyTo property of the notification
463 464 465 |
# File 'lib/coarnotify/core/notify.rb', line 463 def in_reply_to=(value) set_property(ActivityStreams2::Properties::IN_REPLY_TO, value) end |
#object ⇒ NotifyObject?
Get the object property of the notification
436 437 438 439 440 441 442 443 444 |
# File 'lib/coarnotify/core/notify.rb', line 436 def object o = get_property(ActivityStreams2::Properties::OBJECT) if o NotifyObject.new(stream: o, validate_stream_on_construct: false, validate_properties: @validate_properties, validators: @validators, validation_context: ActivityStreams2::Properties::OBJECT, properties_by_reference: @properties_by_reference) end end |
#object=(value) ⇒ Object
Set the object property of the notification
449 450 451 |
# File 'lib/coarnotify/core/notify.rb', line 449 def object=(value) set_property(ActivityStreams2::Properties::OBJECT, value.doc) end |
#origin ⇒ NotifyService?
Get the origin property of the notification
396 397 398 399 400 401 402 403 404 |
# File 'lib/coarnotify/core/notify.rb', line 396 def origin o = get_property(ActivityStreams2::Properties::ORIGIN) if o NotifyService.new(stream: o, validate_stream_on_construct: false, validate_properties: @validate_properties, validators: @validators, validation_context: ActivityStreams2::Properties::ORIGIN, properties_by_reference: @properties_by_reference) end end |
#origin=(value) ⇒ Object
Set the origin property of the notification
409 410 411 |
# File 'lib/coarnotify/core/notify.rb', line 409 def origin=(value) set_property(ActivityStreams2::Properties::ORIGIN, value.doc) end |
#target ⇒ NotifyService?
Get the target property of the notification
416 417 418 419 420 421 422 423 424 |
# File 'lib/coarnotify/core/notify.rb', line 416 def target t = get_property(ActivityStreams2::Properties::TARGET) if t NotifyService.new(stream: t, validate_stream_on_construct: false, validate_properties: @validate_properties, validators: @validators, validation_context: ActivityStreams2::Properties::TARGET, properties_by_reference: @properties_by_reference) end end |
#target=(value) ⇒ Object
Set the target property of the notification
429 430 431 |
# File 'lib/coarnotify/core/notify.rb', line 429 def target=(value) set_property(ActivityStreams2::Properties::TARGET, value.doc) end |
#validate ⇒ Boolean
Base validator for all notification patterns. This extends the validate function on the superclass.
In addition to the base class’s constraints, this applies the following validation:
-
The origin, target and object properties are required and must be valid
-
The actor inReplyTo and context properties are optional, but if present must be valid
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
# File 'lib/coarnotify/core/notify.rb', line 515 def validate ve = ValidationError.new begin super rescue ValidationError => superve ve = superve end required_and_validate(ve, ActivityStreams2::Properties::ORIGIN, origin) required_and_validate(ve, ActivityStreams2::Properties::TARGET, target) required_and_validate(ve, ActivityStreams2::Properties::OBJECT, object) optional_and_validate(ve, ActivityStreams2::Properties::ACTOR, actor) optional_and_validate(ve, ActivityStreams2::Properties::IN_REPLY_TO, in_reply_to) optional_and_validate(ve, ActivityStreams2::Properties::CONTEXT, context) raise ve if ve.has_errors? true end |