Class: Houston::Trigger
- Inherits:
-
Struct
- Object
- Struct
- Houston::Trigger
- Defined in:
- lib/houston/boot/triggers.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#method_name ⇒ Object
Returns the value of attribute method_name.
-
#params ⇒ Object
Returns the value of attribute params.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #call(params = {}) ⇒ Object
-
#initialize(triggers, *args) ⇒ Trigger
constructor
A new instance of Trigger.
- #register! ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(triggers, *args) ⇒ Trigger
Returns a new instance of Trigger.
42 43 44 45 |
# File 'lib/houston/boot/triggers.rb', line 42 def initialize(triggers, *args) @triggers = triggers super *args end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action
40 41 42 |
# File 'lib/houston/boot/triggers.rb', line 40 def action @action end |
#method_name ⇒ Object
Returns the value of attribute method_name
40 41 42 |
# File 'lib/houston/boot/triggers.rb', line 40 def method_name @method_name end |
#params ⇒ Object
Returns the value of attribute params
40 41 42 |
# File 'lib/houston/boot/triggers.rb', line 40 def params @params end |
#value ⇒ Object
Returns the value of attribute value
40 41 42 |
# File 'lib/houston/boot/triggers.rb', line 40 def value @value end |
Instance Method Details
#call(params = {}) ⇒ Object
55 56 57 58 |
# File 'lib/houston/boot/triggers.rb', line 55 def call(params={}) = { trigger: to_s, async: triggers.async } config.actions.run action, self.params.merge(params.to_h), end |
#register! ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/houston/boot/triggers.rb', line 47 def register! case method_name when :every then config.timer.every(value, &method(:call)) when :on then config.observer.on(value, &method(:call)) else raise NotImplementedError, "Unrecognized method name: #{method_name.inspect}" end end |
#to_s ⇒ Object
60 61 62 |
# File 'lib/houston/boot/triggers.rb', line 60 def to_s "#{method_name}(#{value})" end |