Class: Houston::Triggers

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/houston/boot/triggers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Triggers

Returns a new instance of Triggers.



11
12
13
14
15
# File 'lib/houston/boot/triggers.rb', line 11

def initialize(config)
  @config = config
  @async = true
  super Concurrent::Array.new
end

Instance Attribute Details

#asyncObject

Returns the value of attribute async.



9
10
11
# File 'lib/houston/boot/triggers.rb', line 9

def async
  @async
end

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/houston/boot/triggers.rb', line 8

def config
  @config
end

Instance Method Details

#build(method_name, value, action, params, persistent_trigger_id: nil) ⇒ Object



26
27
28
# File 'lib/houston/boot/triggers.rb', line 26

def build(method_name, value, action, params, persistent_trigger_id: nil)
  Trigger.new(self, method_name, value, action, params, persistent_trigger_id)
end

#delete(trigger) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/houston/boot/triggers.rb', line 37

def delete(trigger)
  i = find_index(trigger)
  return unless i
  trigger = self[i]
  trigger.unregister!
  delete_at i
end

#every(value, action, params = {}) ⇒ Object



18
19
20
# File 'lib/houston/boot/triggers.rb', line 18

def every(value, action, params={})
  push build(:every, value, action, params)
end

#on(event, action, params = {}) ⇒ Object



22
23
24
# File 'lib/houston/boot/triggers.rb', line 22

def on(event, action, params={})
  push build(:on, event, action, params)
end

#push(trigger) ⇒ Object



30
31
32
33
34
35
# File 'lib/houston/boot/triggers.rb', line 30

def push(trigger)
  raise DuplicateTriggerError, "That exact trigger has already been defined" if member?(trigger)
  super trigger
  trigger.register!
  trigger
end