Class: Smith::Workflow::MessageAdmission
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Smith::Workflow::MessageAdmission
- Defined in:
- lib/smith/workflow/message_admission.rb
Instance Attribute Summary collapse
-
#message_digest ⇒ Object
readonly
Returns the value of attribute message_digest.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ MessageAdmission
constructor
A new instance of MessageAdmission.
- #message_count ⇒ Object
Constructor Details
#initialize(attributes) ⇒ MessageAdmission
Returns a new instance of MessageAdmission.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/smith/workflow/message_admission.rb', line 21 def initialize(attributes) normalized = MessageValueNormalizer.new(attributes.fetch(:messages)).call payload = JSON.generate(normalized, max_nesting: MessageValueNormalizer::MAX_DEPTH) if payload.bytesize > MessageValueNormalizer::MAX_BYTES raise WorkflowError, "session message batch exceeds maximum bytes #{MessageValueNormalizer::MAX_BYTES}" end super(messages: normalized) @message_digest = Digest::SHA256.hexdigest(payload).freeze self.attributes.freeze freeze rescue JSON::GeneratorError, JSON::NestingError => e raise WorkflowError, "session message batch is not canonical JSON: #{e.}" end |
Instance Attribute Details
#message_digest ⇒ Object (readonly)
Returns the value of attribute message_digest.
19 20 21 |
# File 'lib/smith/workflow/message_admission.rb', line 19 def @message_digest end |
Instance Method Details
#message_count ⇒ Object
37 |
# File 'lib/smith/workflow/message_admission.rb', line 37 def = .length |