Class: Carnivore::Callback
- Inherits:
-
Object
- Object
- Carnivore::Callback
- Includes:
- Utils::Logging, Celluloid
- Defined in:
- lib/carnivore/callback.rb
Overview
Payload modifier
Class Attribute Summary (collapse)
-
+ (Object) workers
Define number of workers to create.
Instance Attribute Summary (collapse)
-
- (String, Symbol) name
readonly
Name of callback.
-
- (Carnivore::Source) source
readonly
Source this callback is attached.
Instance Method Summary (collapse)
-
- (Object) call(message)
Execute callback against given message.
-
- (Callback) initialize(name, source, block = nil)
constructor
Creates a new callback.
-
- (String) inspect
(also: #to_s)
Provide nice output when printed.
-
- (NilClass) log(*args)
included
from Utils::Logging
Log message.
-
- (Object) setup
Used by custom callback classes for setup.
-
- (TrueClass, FalseClass) valid?(message)
Message is valid for this callback.
Constructor Details
- (Callback) initialize(name, source, block = nil)
Creates a new callback. Optional block to define callback behavior must be passed as a `Proc` instance, not a block.
26 27 28 29 30 31 32 33 34 |
# File 'lib/carnivore/callback.rb', line 26 def initialize(name, source, block=nil) @name = name @source = source if(block.nil? && self.class == Callback) raise ArgumentError.new 'Block is required for dynamic callbacks!' end define_singleton_method(:execute, &block) if block setup end |
Class Attribute Details
+ (Object) workers
Define number of workers to create
9 10 11 |
# File 'lib/carnivore/callback.rb', line 9 def workers @workers end |
Instance Attribute Details
- (String, Symbol) name (readonly)
Returns name of callback
17 18 19 |
# File 'lib/carnivore/callback.rb', line 17 def name @name end |
- (Carnivore::Source) source (readonly)
Returns source this callback is attached
19 20 21 |
# File 'lib/carnivore/callback.rb', line 19 def source @source end |
Instance Method Details
- (Object) call(message)
Execute callback against given message
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/carnivore/callback.rb', line 60 def call() begin if(valid?()) debug ">> Received message is valid for this callback (#{})" execute() else debug "Invalid message for this callback #{})" end rescue => e error "[callback: #{self}, source: #{[:source]}, message: #{[:message].object_id}]: #{e.class} - #{e}" debug "#{e.class}: #{e}\n#{e.backtrace.join("\n")}" nil end end |
- (String) inspect Also known as: to_s
Provide nice output when printed
44 45 46 |
# File 'lib/carnivore/callback.rb', line 44 def inspect "callback<#{self.name}:#{self.object_id}>" end |
- (NilClass) log(*args) Originally defined in module Utils::Logging
Log message
- (Object) setup
Used by custom callback classes for setup
37 38 39 |
# File 'lib/carnivore/callback.rb', line 37 def setup debug 'No custom setup defined' end |
- (TrueClass, FalseClass) valid?(message)
Message is valid for this callback
53 54 55 |
# File 'lib/carnivore/callback.rb', line 53 def valid?() true end |