Class: Courier::Templates::RoutingStrategy
- Inherits:
-
Object
- Object
- Courier::Templates::RoutingStrategy
- Defined in:
- lib/trycourier/templates/types/routing_strategy.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Templates::RoutingStrategy
Deserialize a JSON object to an instance of RoutingStrategy.
-
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
Instance Method Summary collapse
- #initialize(method:, channels:, additional_properties: nil) ⇒ Templates::RoutingStrategy constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of RoutingStrategy to a JSON object.
Constructor Details
#initialize(method:, channels:, additional_properties: nil) ⇒ Templates::RoutingStrategy
16 17 18 19 20 21 22 23 |
# File 'lib/trycourier/templates/types/routing_strategy.rb', line 16 def initialize(method:, channels:, additional_properties: nil) # @type [Templates::RoutingStrategyMethod] The method for selecting channels to send the message with. Value can be either 'single' or 'all'. If not provided will default to 'single' @method = method # @type [Array<Templates::CHANNEL_IDENTIFIER>] An array of valid channel identifiers (like email, push, sms, etc.) and additional routing nodes. @channels = channels # @type [OpenStruct] Additional properties unmapped to the current class definition @additional_properties = additional_properties end |
Instance Attribute Details
#additional_properties ⇒ Object (readonly)
Returns the value of attribute additional_properties.
10 11 12 |
# File 'lib/trycourier/templates/types/routing_strategy.rb', line 10 def additional_properties @additional_properties end |
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
10 11 12 |
# File 'lib/trycourier/templates/types/routing_strategy.rb', line 10 def channels @channels end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
10 11 12 |
# File 'lib/trycourier/templates/types/routing_strategy.rb', line 10 def method @method end |
Class Method Details
.from_json(json_object:) ⇒ Templates::RoutingStrategy
Deserialize a JSON object to an instance of RoutingStrategy
29 30 31 32 33 34 35 |
# File 'lib/trycourier/templates/types/routing_strategy.rb', line 29 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) JSON.parse(json_object) method = struct.method channels = struct.channels new(method: method, channels: channels, additional_properties: struct) end |
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
48 49 50 51 |
# File 'lib/trycourier/templates/types/routing_strategy.rb', line 48 def self.validate_raw(obj:) obj.method.is_a?(Templates::RoutingStrategyMethod) != false || raise("Passed value for field obj.method is not the expected type, validation failed.") obj.channels.is_a?(Array) != false || raise("Passed value for field obj.channels is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ JSON
Serialize an instance of RoutingStrategy to a JSON object
40 41 42 |
# File 'lib/trycourier/templates/types/routing_strategy.rb', line 40 def to_json(*_args) { "method": @method, "channels": @channels }.to_json end |