Class: Event

Inherits:
MLS::Model show all
Defined in:
lib/mls/models/event.rb

Constant Summary collapse

SOURCE_TYPES =
%w(call email website)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.encapsulate(options = {}, &block) ⇒ Object

Allow you to encapsulate all modification to be attached to a single event

Event.encapsulate(source: '...', source_type: 'API') do
  ...
end

Returns the event is needed in the future



35
36
37
38
39
40
41
42
43
# File 'lib/mls/models/event.rb', line 35

def self.encapsulate(options={}, &block)
  event = Event.create!(options)
  Thread.current[:sunstone_headers] ||= {}
  Thread.current[:sunstone_headers]['Event-Id'] = event.id
  yield
  event
ensure
  Thread.current[:sunstone_headers].try(:delete, 'Event-Id')
end

Instance Method Details

#encapsulate(&block) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/mls/models/event.rb', line 19

def encapsulate(&block)
  Thread.current[:sunstone_headers] ||= {}
  Thread.current[:sunstone_headers]['Event-Id'] = self.id
  yield
  self
ensure
  Thread.current[:sunstone_headers].delete('Event-Id')
end

#regardingObject



15
16
17
# File 'lib/mls/models/event.rb', line 15

def regarding
  regards.map(&:thing)
end