Class: Triggerable::Engine
- Inherits:
-
Object
- Object
- Triggerable::Engine
- Defined in:
- lib/triggerable/engine.rb
Class Method Summary collapse
- .automation(model, options, block) ⇒ Object
- .clear ⇒ Object
- .log(level, message) ⇒ Object
- .run_automations(interval) ⇒ Object
- .trigger(model, options, block) ⇒ Object
- .triggers_for(obj, callback) ⇒ Object
Class Method Details
.automation(model, options, block) ⇒ Object
18 19 20 |
# File 'lib/triggerable/engine.rb', line 18 def self.automation model, , block self.automations << Rules::Automation.new(model, , block) end |
.clear ⇒ Object
32 33 34 35 |
# File 'lib/triggerable/engine.rb', line 32 def self.clear self.triggers = [] self.automations = [] end |
.log(level, message) ⇒ Object
37 38 39 40 |
# File 'lib/triggerable/engine.rb', line 37 def self.log level, puts if debug logger.send(level, "#{Time.now.strftime('%FT%T%z')}: #{}") if logger.present? end |
.run_automations(interval) ⇒ Object
26 27 28 29 30 |
# File 'lib/triggerable/engine.rb', line 26 def self.run_automations interval self.interval = interval return unless Triggerable.enabled? automations.each(&:execute!) end |
.trigger(model, options, block) ⇒ Object
14 15 16 |
# File 'lib/triggerable/engine.rb', line 14 def self.trigger model, , block self.triggers << Rules::Trigger.new(model, , block) end |
.triggers_for(obj, callback) ⇒ Object
22 23 24 |
# File 'lib/triggerable/engine.rb', line 22 def self.triggers_for obj, callback triggers.select { |t| obj.class.name == t.model.name && t.callback == callback } end |