Sha256: 0a5c4ef2677e838838736cb1385b9f27a6978d4476bddf7009455721403660b8
Contents?: true
Size: 1.28 KB
Versions: 9
Compression:
Stored size: 1.28 KB
Contents
module WaterDrop # Aspects module which include all available aspects module Aspects # Base class for all aspects class BaseAspect < ::Aspector::Base default private_methods: true # @param this is an instance on which we execute aspect (original method caller) # @param [Hash] options aspect options # @param [Array] args original method arguments # @param [Block] message block which we evaluate to get a message that we will send # @param result original method result def handle(this, options, args, message, *result) formatter = Formatter.new( options, args, instance_run(this, result, message) ) Message.new(options[:topic], formatter.message).send! end private # Method used to change message block binding, so it will be evaluated # in the caller instance context # @param this is an instance on which we execute aspect (original method caller) # @param result original method call result # @param [Block] message block def instance_run(this, result, message) return this.instance_eval(&message) if message.parameters.empty? this.instance_exec(result, message) { |res, block| block.call(res.first) } end end end end
Version data entries
9 entries across 9 versions & 1 rubygems