Class: Arcp::Job::Event

Inherits:
Data
  • Object
show all
Defined in:
lib/arcp/job/event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



50
51
52
# File 'lib/arcp/job/event.rb', line 50

def body
  @body
end

#kindObject (readonly)

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



50
51
52
# File 'lib/arcp/job/event.rb', line 50

def kind
  @kind
end

Class Method Details

.from_h(h) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/arcp/job/event.rb', line 51

def self.from_h(h)
  h = h.transform_keys(&:to_s)
  kind = h.fetch('kind')
  body_h = h['body'] || {}
  klass = BODY_CLASSES[kind]
  body = klass ? klass.from_h(body_h) : Arcp::Envelope.deep_freeze(body_h.dup)
  new(kind: kind, body: body)
end

Instance Method Details

#known?Boolean

Returns:

  • (Boolean)


65
# File 'lib/arcp/job/event.rb', line 65

def known? = EventKind::ALL.include?(kind)

#to_hObject



60
61
62
63
# File 'lib/arcp/job/event.rb', line 60

def to_h
  body_h = body.respond_to?(:to_h) ? body.to_h : body
  { 'kind' => kind, 'body' => body_h }
end