class Tantot::Agent::Block
Public Class Methods
identify(watch)
click to toggle source
# File lib/tantot/agent/block.rb, line 6 def self.identify(watch) if watch.block.present? CityHash.hash64("#{watch.model.to_s}|#{watch.attributes.inspect}|#{watch.options.inspect}") else nil end end
Public Instance Methods
debug_block(block)
click to toggle source
# File lib/tantot/agent/block.rb, line 27 def debug_block(block) location, line = block.source_location short_path = defined?(Rails) ? Pathname.new(location).relative_path_from(Rails.root).to_s : location "block @ #{short_path}##{line}" end
debug_id()
click to toggle source
# File lib/tantot/agent/block.rb, line 33 def debug_id debug_block(watches.first.block) end
perform(changes_by_model)
click to toggle source
# File lib/tantot/agent/block.rb, line 18 def perform(changes_by_model) # Block agent always has only one watch block = watches.first.block model = watches.first.model # Skip the model part of the changes since it will always be on a # single model, and wrap it in the ById helper. model.instance_exec(Tantot::Changes::ById.new(changes_by_model.values.first), &block) end
setup_watch(watch)
click to toggle source
# File lib/tantot/agent/block.rb, line 14 def setup_watch(watch) raise Tantot::MultipleWatchesProhibited.new("Can't have multiple block watches per model with the same attributes and options: #{debug_block(watch.block)}") if @watches.any? end