Class: Scjson::Types::OnexitProps
- Inherits:
-
Object
- Object
- Scjson::Types::OnexitProps
- Defined in:
- lib/scjson/types.rb
Overview
Structured type for scjson elements.
Instance Attribute Summary collapse
-
#assign ⇒ Object
Returns the value of attribute assign.
-
#cancel ⇒ Object
Returns the value of attribute cancel.
-
#foreach ⇒ Object
Returns the value of attribute foreach.
-
#if_value ⇒ Object
Returns the value of attribute if_value.
-
#log ⇒ Object
Returns the value of attribute log.
-
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
-
#other_element ⇒ Object
Returns the value of attribute other_element.
-
#raise_value ⇒ Object
Returns the value of attribute raise_value.
-
#script ⇒ Object
Returns the value of attribute script.
-
#send ⇒ Object
Returns the value of attribute send.
Class Method Summary collapse
-
.from_hash(data) ⇒ OnexitProps
Build an instance from a Hash representation.
-
.from_json(json) ⇒ OnexitProps
Deserialize an instance from a JSON payload.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ OnexitProps
constructor
Instantiate a new OnexitProps object.
-
#to_hash ⇒ Hash
Convert the object to a Hash suitable for JSON serialization.
-
#to_json(*opts) ⇒ String
Serialize the object to JSON.
Constructor Details
#initialize(**kwargs) ⇒ OnexitProps
Instantiate a new OnexitProps object.
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 |
# File 'lib/scjson/types.rb', line 1304 def initialize(**kwargs) @other_element = kwargs.fetch(:other_element, []) @raise_value = kwargs.fetch(:raise_value, []) @if_value = kwargs.fetch(:if_value, []) @foreach = kwargs.fetch(:foreach, []) @send = kwargs.fetch(:send, []) @script = kwargs.fetch(:script, []) @assign = kwargs.fetch(:assign, []) @log = kwargs.fetch(:log, []) @cancel = kwargs.fetch(:cancel, []) @other_attributes = kwargs.fetch(:other_attributes, {}) end |
Instance Attribute Details
#assign ⇒ Object
Returns the value of attribute assign.
1301 1302 1303 |
# File 'lib/scjson/types.rb', line 1301 def assign @assign end |
#cancel ⇒ Object
Returns the value of attribute cancel.
1301 1302 1303 |
# File 'lib/scjson/types.rb', line 1301 def cancel @cancel end |
#foreach ⇒ Object
Returns the value of attribute foreach.
1301 1302 1303 |
# File 'lib/scjson/types.rb', line 1301 def foreach @foreach end |
#if_value ⇒ Object
Returns the value of attribute if_value.
1301 1302 1303 |
# File 'lib/scjson/types.rb', line 1301 def if_value @if_value end |
#log ⇒ Object
Returns the value of attribute log.
1301 1302 1303 |
# File 'lib/scjson/types.rb', line 1301 def log @log end |
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
1301 1302 1303 |
# File 'lib/scjson/types.rb', line 1301 def other_attributes @other_attributes end |
#other_element ⇒ Object
Returns the value of attribute other_element.
1301 1302 1303 |
# File 'lib/scjson/types.rb', line 1301 def other_element @other_element end |
#raise_value ⇒ Object
Returns the value of attribute raise_value.
1301 1302 1303 |
# File 'lib/scjson/types.rb', line 1301 def raise_value @raise_value end |
#script ⇒ Object
Returns the value of attribute script.
1301 1302 1303 |
# File 'lib/scjson/types.rb', line 1301 def script @script end |
#send ⇒ Object
Returns the value of attribute send.
1301 1302 1303 |
# File 'lib/scjson/types.rb', line 1301 def send @send end |
Class Method Details
.from_hash(data) ⇒ OnexitProps
Build an instance from a Hash representation.
1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 |
# File 'lib/scjson/types.rb', line 1320 def self.from_hash(data) raise ArgumentError, 'Expected Hash' unless data.is_a?(Hash) normalized = data.transform_keys(&:to_s) kwargs = {} kwargs[:other_element] = Array(normalized.fetch('other_element', [])) kwargs[:raise_value] = Array(normalized.fetch('raise_value', [])).map { |item| RaiseProps.from_hash(item) } kwargs[:if_value] = Array(normalized.fetch('if_value', [])).map { |item| IfProps.from_hash(item) } kwargs[:foreach] = Array(normalized.fetch('foreach', [])).map { |item| ForeachProps.from_hash(item) } kwargs[:send] = Array(normalized.fetch('send', [])).map { |item| SendProps.from_hash(item) } kwargs[:script] = Array(normalized.fetch('script', [])).map { |item| ScriptProps.from_hash(item) } kwargs[:assign] = Array(normalized.fetch('assign', [])).map { |item| AssignProps.from_hash(item) } kwargs[:log] = Array(normalized.fetch('log', [])).map { |item| LogProps.from_hash(item) } kwargs[:cancel] = Array(normalized.fetch('cancel', [])).map { |item| CancelProps.from_hash(item) } kwargs[:other_attributes] = normalized.fetch('other_attributes', {}) new(**kwargs) end |
.from_json(json) ⇒ OnexitProps
Deserialize an instance from a JSON payload.
1341 1342 1343 1344 |
# File 'lib/scjson/types.rb', line 1341 def self.from_json(json) parsed = JSON.parse(json) from_hash(parsed) end |
Instance Method Details
#to_hash ⇒ Hash
Convert the object to a Hash suitable for JSON serialization.
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 |
# File 'lib/scjson/types.rb', line 1348 def to_hash { 'other_element' => @other_element, 'raise_value' => (@raise_value || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'if_value' => (@if_value || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'foreach' => (@foreach || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'send' => (@send || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'script' => (@script || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'assign' => (@assign || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'log' => (@log || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'cancel' => (@cancel || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'other_attributes' => @other_attributes } end |
#to_json(*opts) ⇒ String
Serialize the object to JSON.
1366 1367 1368 |
# File 'lib/scjson/types.rb', line 1366 def to_json(*opts) JSON.generate(to_hash, *opts) end |