Class: Device::NotificationCallback

Inherits:
Object
  • Object
show all
Defined in:
lib/device/notification_callback.rb

Constant Summary collapse

CallbackResult =
DaFunk::Struct.klass(:before_execute, :result, :after_execute)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, procs = {}) ⇒ NotificationCallback

Returns a new instance of NotificationCallback.



8
9
10
11
12
13
14
15
# File 'lib/device/notification_callback.rb', line 8

def initialize(description, procs = {})
  @description = description
  @on          = procs[:on]
  @before      = procs[:before]
  @after       = procs[:after]
  @results     = {:on => [], :before => [], :after => []}
  schedule!
end

Instance Attribute Details

#afterObject (readonly)

Returns the value of attribute after.



3
4
5
# File 'lib/device/notification_callback.rb', line 3

def after
  @after
end

#beforeObject (readonly)

Returns the value of attribute before.



3
4
5
# File 'lib/device/notification_callback.rb', line 3

def before
  @before
end

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/device/notification_callback.rb', line 3

def description
  @description
end

#onObject (readonly)

Returns the value of attribute on.



3
4
5
# File 'lib/device/notification_callback.rb', line 3

def on
  @on
end

#resultsObject

Returns the value of attribute results.



4
5
6
# File 'lib/device/notification_callback.rb', line 4

def results
  @results
end

Instance Method Details

#call(event, moment = :on) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/device/notification_callback.rb', line 21

def call(event, moment = :on)
  if support?(moment)
    results[moment] << CallbackResult.call(
      Time.now,
      perform(event, moment),
      Time.now
    )
  end
end

#schedule!Object



17
18
19
# File 'lib/device/notification_callback.rb', line 17

def schedule!
  Notification.schedule(self)
end