Class: EventPeople::Event

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, body, schema_version = 1.0) ⇒ Event

Returns a new instance of Event.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/event_people/event.rb', line 5

def initialize(name, body, schema_version = 1.0)
  @name = name
  @body = body.is_a?(String) ? JSON.parse(body) : body
  @schema_version = @body&.dig('headers', 'schemaVersion') || schema_version

  if name?
    generate_headers
    fix_name
  end

  build_payload if @body&.key?('headers')
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/event_people/event.rb', line 3

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



3
4
5
# File 'lib/event_people/event.rb', line 3

def headers
  @headers
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/event_people/event.rb', line 3

def name
  @name
end

#schema_versionObject (readonly)

Returns the value of attribute schema_version.



3
4
5
# File 'lib/event_people/event.rb', line 3

def schema_version
  @schema_version
end

Instance Method Details

#body?Boolean

Returns:

  • (Boolean)


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

def body?
  body && !body.empty?
end

#name?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/event_people/event.rb', line 26

def name?
  name && !name.empty?
end

#payloadObject



18
19
20
# File 'lib/event_people/event.rb', line 18

def payload
  { headers: headers, body: body }.to_json
end