Class: Scjson::Types::RaiseProps
- Inherits:
-
Object
- Object
- Scjson::Types::RaiseProps
- Defined in:
- lib/scjson/types.rb
Overview
raise an internal event.
Instance Attribute Summary collapse
-
#event ⇒ Object
Returns the value of attribute event.
-
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
Class Method Summary collapse
-
.from_hash(data) ⇒ RaiseProps
Build an instance from a Hash representation.
-
.from_json(json) ⇒ RaiseProps
Deserialize an instance from a JSON payload.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ RaiseProps
constructor
Instantiate a new RaiseProps 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) ⇒ RaiseProps
Instantiate a new RaiseProps object.
1517 1518 1519 1520 |
# File 'lib/scjson/types.rb', line 1517 def initialize(**kwargs) @event = kwargs.fetch(:event, '') @other_attributes = kwargs.fetch(:other_attributes, {}) end |
Instance Attribute Details
#event ⇒ Object
Returns the value of attribute event.
1514 1515 1516 |
# File 'lib/scjson/types.rb', line 1514 def event @event end |
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
1514 1515 1516 |
# File 'lib/scjson/types.rb', line 1514 def other_attributes @other_attributes end |
Class Method Details
.from_hash(data) ⇒ RaiseProps
Build an instance from a Hash representation.
1525 1526 1527 1528 1529 1530 1531 1532 1533 |
# File 'lib/scjson/types.rb', line 1525 def self.from_hash(data) raise ArgumentError, 'Expected Hash' unless data.is_a?(Hash) normalized = data.transform_keys(&:to_s) kwargs = {} kwargs[:event] = normalized.fetch('event', '') kwargs[:other_attributes] = normalized.fetch('other_attributes', {}) new(**kwargs) end |
.from_json(json) ⇒ RaiseProps
Deserialize an instance from a JSON payload.
1538 1539 1540 1541 |
# File 'lib/scjson/types.rb', line 1538 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.
1545 1546 1547 1548 1549 1550 |
# File 'lib/scjson/types.rb', line 1545 def to_hash { 'event' => @event, 'other_attributes' => @other_attributes } end |
#to_json(*opts) ⇒ String
Serialize the object to JSON.
1555 1556 1557 |
# File 'lib/scjson/types.rb', line 1555 def to_json(*opts) JSON.generate(to_hash, *opts) end |