Class: Inngest::Event
- Inherits:
-
Object
- Object
- Inngest::Event
- Defined in:
- lib/inngest.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#name ⇒ Object
Returns the value of attribute name.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#user ⇒ Object
Returns the value of attribute user.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(name: nil, data: {}, user: {}, version: nil, timestamp: nil) ⇒ Event
constructor
A new instance of Event.
- #payload ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(name: nil, data: {}, user: {}, version: nil, timestamp: nil) ⇒ Event
50 51 52 53 54 55 56 |
# File 'lib/inngest.rb', line 50 def initialize (name: nil, data: {}, user: {}, version: nil, timestamp: nil) @name = name @data = data @user = user @version = version = ? : Time.now.to_i * 1000 end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
48 49 50 |
# File 'lib/inngest.rb', line 48 def data @data end |
#name ⇒ Object
Returns the value of attribute name.
48 49 50 |
# File 'lib/inngest.rb', line 48 def name @name end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
48 49 50 |
# File 'lib/inngest.rb', line 48 def end |
#user ⇒ Object
Returns the value of attribute user.
48 49 50 |
# File 'lib/inngest.rb', line 48 def user @user end |
#version ⇒ Object
Returns the value of attribute version.
48 49 50 |
# File 'lib/inngest.rb', line 48 def version @version end |
Instance Method Details
#payload ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/inngest.rb', line 75 def payload { name: @name, data: @data, user: @user, v: @version, ts: }.compact end |
#validate ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/inngest.rb', line 58 def validate unless @name&.strip raise InngestException.new "Event name can't be empty" end unless @data raise InngestException.new "Event data can't be empty" end begin @data.to_json rescue Exception raise InngestException.new "Event data couldn't be serialized to json" end end |