Class: Noticent::Definitions::Hooks
- Inherits:
-
Object
- Object
- Noticent::Definitions::Hooks
- Defined in:
- lib/noticent/definitions/hooks.rb
Constant Summary collapse
- VALID_STEPS =
%i[pre_alert_registration post_alert_registration pre_channel_registration post_channel_registration pre_product_registration post_product_registration].freeze
Instance Method Summary collapse
Instance Method Details
#add(step, klass) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/noticent/definitions/hooks.rb', line 8 def add(step, klass) raise BadConfiguration, "invalid step. valid values are #{VALID_STEPS}" unless VALID_STEPS.include? step raise BadConfiguration, "hook #{klass} doesn't have a #{step} method" unless klass.respond_to? step storage[step] = [] if storage[step].nil? storage[step] << klass end |
#fetch(step) ⇒ Object
16 17 18 19 20 |
# File 'lib/noticent/definitions/hooks.rb', line 16 def fetch(step) raise ::ArgumentError, "invalid step. valid values are #{VALID_STEPS}" unless VALID_STEPS.include? step storage[step] end |
#run(step, chan) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/noticent/definitions/hooks.rb', line 22 def run(step, chan) chain = fetch(step) return if chain.nil? chain.each do |to_run| to_run.send(step, chan) if to_run.respond_to? step end end |