Class: Scjson::Types::RaiseProps

Inherits:
Object
  • Object
show all
Defined in:
lib/scjson/types.rb

Overview

raise an internal event.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ RaiseProps

Instantiate a new RaiseProps object.

Parameters:

  • kwargs (Hash)

    Optional keyword overrides.



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

#eventObject

Returns the value of attribute event.



1514
1515
1516
# File 'lib/scjson/types.rb', line 1514

def event
  @event
end

#other_attributesObject

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.

Parameters:

  • data (Hash)

    Canonical hash representation.

Returns:

Raises:

  • (ArgumentError)


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.

Parameters:

  • json (String)

    JSON document to decode.

Returns:



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_hashHash

Convert the object to a Hash suitable for JSON serialization.

Returns:

  • (Hash)


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.

Parameters:

  • opts (Array)

    JSON generation options.

Returns:

  • (String)


1555
1556
1557
# File 'lib/scjson/types.rb', line 1555

def to_json(*opts)
  JSON.generate(to_hash, *opts)
end