Class: Coarnotify::Core::Notify::NotifyPatternPart
- Inherits:
-
NotifyBase
- Object
- NotifyBase
- Coarnotify::Core::Notify::NotifyPatternPart
- Defined in:
- lib/coarnotify/core/notify.rb
Overview
Base class for all pattern parts, such as objects, contexts, actors, etc
If there is a default type specified, and a type is not given at construction, then the default type will be added
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from NotifyBase
#properties_by_reference, #validate_properties, #validate_stream_on_construct, #validators
Class Method Summary collapse
-
.allowed_types ⇒ Object
The list of types that are permissible for this object.
-
.default_type ⇒ Object
The default type for this object, if none is provided on construction.
Instance Method Summary collapse
-
#allowed_types ⇒ Array<String>
Get the allowed types for this object.
-
#initialize(stream: nil, validate_stream_on_construct: true, validate_properties: true, validators: nil, validation_context: nil, properties_by_reference: true) ⇒ NotifyPatternPart
constructor
Constructor for the NotifyPatternPart.
-
#type=(types) ⇒ Object
Set the type of the object, and validate that it is one of the allowed types if present.
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, #validate, #validate_property
Constructor Details
#initialize(stream: nil, validate_stream_on_construct: true, validate_properties: true, validators: nil, validation_context: nil, properties_by_reference: true) ⇒ NotifyPatternPart
Constructor for the NotifyPatternPart
If there is a default type specified, and a type is not given at construction, then the default type will be added
561 562 563 564 565 566 567 |
# File 'lib/coarnotify/core/notify.rb', line 561 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) self.type = self.class.default_type if self.class.default_type && type.nil? end |
Class Method Details
.allowed_types ⇒ Object
The list of types that are permissible for this object. If the list is empty, then any type is allowed
546 547 548 |
# File 'lib/coarnotify/core/notify.rb', line 546 def self.allowed_types [] end |
.default_type ⇒ Object
The default type for this object, if none is provided on construction
541 542 543 |
# File 'lib/coarnotify/core/notify.rb', line 541 def self.default_type nil end |
Instance Method Details
#allowed_types ⇒ Array<String>
Get the allowed types for this object
572 573 574 |
# File 'lib/coarnotify/core/notify.rb', line 572 def allowed_types self.class.allowed_types end |
#type=(types) ⇒ Object
Set the type of the object, and validate that it is one of the allowed types if present
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
# File 'lib/coarnotify/core/notify.rb', line 579 def type=(types) types = [types] unless types.is_a?(Array) if !allowed_types.empty? types.each do |t| unless allowed_types.include?(t) raise ArgumentError, "Type value #{t} is not one of the permitted values" end end end # keep single values as single values, not arrays types = types.length == 1 ? types[0] : types set_property(ActivityStreams2::Properties::TYPE, types) end |