Class: Midnight::BusinessLogic::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/midnight/business_logic/event.rb

Defined Under Namespace

Classes: SchemaViolation

Constant Summary collapse

DEFAULT_METADATA_GENERATOR =
lambda do
  {
    occurred_at: ::Time.current.iso8601(6)
  }
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data: {}, metadata: nil) ⇒ Event

Returns a new instance of Event.



16
17
18
19
20
# File 'lib/midnight/business_logic/event.rb', line 16

def initialize(data: {}, metadata: nil)
  @data = data
  @metadata =  || DEFAULT_METADATA_GENERATOR.call
  freeze
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



22
23
24
# File 'lib/midnight/business_logic/event.rb', line 22

def data
  @data
end

#metadataObject (readonly)

Returns the value of attribute metadata.



22
23
24
# File 'lib/midnight/business_logic/event.rb', line 22

def 
  @metadata
end

Class Method Details

.strict(data: {}, metadata: nil) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/midnight/business_logic/event.rb', line 25

def strict(data: {}, metadata: nil)
  ensure_schema(data)
  new(
    data: data,
    metadata: 
  )
end