class Tantot::Agent::Watcher

Public Class Methods

derive_watcher(name) click to toggle source
# File lib/tantot/agent/watcher.rb, line 14
def self.derive_watcher(name)
  watcher =
    if name.is_a?(Class)
      name
    else
      class_name = "#{name.camelize}Watcher"
      watcher = class_name.safe_constantize
      raise Tantot::UnderivableWatcher, "Can not find watcher named `#{class_name}`" unless watcher
      watcher
    end
  raise Tantot::UnderivableWatcher, "Watcher class does not include Tantot::Watcher: #{watcher}" unless watcher.included_modules.include?(Tantot::Watcher)
  watcher
end
identify(watch) click to toggle source
# File lib/tantot/agent/watcher.rb, line 6
def self.identify(watch)
  if watch.watcher.present?
    derive_watcher(watch.watcher)
  else
    nil
  end
end

Public Instance Methods

debug_id() click to toggle source
# File lib/tantot/agent/watcher.rb, line 41
def debug_id
  id.name
end
perform(changes_by_model) click to toggle source
# File lib/tantot/agent/watcher.rb, line 37
def perform(changes_by_model)
  watcher.new.perform(Tantot::Changes::ByModel.new(changes_by_model))
end
setup_watch(watch) click to toggle source
# File lib/tantot/agent/watcher.rb, line 33
def setup_watch(watch)
  watch.options.reverse_merge!(watcher.watcher_options)
end
watcher() click to toggle source
# File lib/tantot/agent/watcher.rb, line 28
def watcher
  # The id of the agent is the watcher class (see self#identify)
  id
end