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.
-
#persistent_trigger_id ⇒ Object
Returns the value of attribute persistent_trigger_id.
-
#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
- #unregister! ⇒ Object
Constructor Details
#initialize(triggers, *args) ⇒ Trigger
Returns a new instance of Trigger.
54 55 56 57 58 |
# File 'lib/houston/boot/triggers.rb', line 54 def initialize(triggers, *args) @triggers = triggers @callback = method(:call).to_proc super *args end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action
52 53 54 |
# File 'lib/houston/boot/triggers.rb', line 52 def action @action end |
#method_name ⇒ Object
Returns the value of attribute method_name
52 53 54 |
# File 'lib/houston/boot/triggers.rb', line 52 def method_name @method_name end |
#params ⇒ Object
Returns the value of attribute params
52 53 54 |
# File 'lib/houston/boot/triggers.rb', line 52 def params @params end |
#persistent_trigger_id ⇒ Object
Returns the value of attribute persistent_trigger_id
52 53 54 |
# File 'lib/houston/boot/triggers.rb', line 52 def persistent_trigger_id @persistent_trigger_id end |
#value ⇒ Object
Returns the value of attribute value
52 53 54 |
# File 'lib/houston/boot/triggers.rb', line 52 def value @value end |
Instance Method Details
#call(params = {}) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/houston/boot/triggers.rb', line 76 def call(params={}) Rails.logger.info "\e[34m[#{to_s} => #{action}]\e[0m" config.actions.run action, self.params.merge(params.to_h), trigger: to_s, async: triggers.async end |
#register! ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/houston/boot/triggers.rb', line 60 def register! case method_name when :every then config.timer.every(value, &callback) when :on then config.observer.on(value, &callback) else raise NotImplementedError, "Unrecognized method name: #{method_name.inspect}" end end |
#to_s ⇒ Object
83 84 85 |
# File 'lib/houston/boot/triggers.rb', line 83 def to_s "#{method_name}(#{value})" end |
#unregister! ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/houston/boot/triggers.rb', line 68 def unregister! case method_name when :every then config.timer.stop(value, callback) when :on then config.observer.off(value, &callback) else raise NotImplementedError, "Unrecognized method name: #{method_name.inspect}" end end |