Sha256: c3faf72ebe1dcef4d4d0d02073aed849de71c49bf9ea371ec101c8b40e93e81b
Contents?: true
Size: 992 Bytes
Versions: 4
Compression:
Stored size: 992 Bytes
Contents
require 'slappy/listeners/concerns/targettable' require 'slappy/listeners/concerns/validatable' module Slappy module Listener class Base include Validatable include Targettable def initialize(pattern, options = {}, &callback) self.pattern = pattern if options[:from] target.channel = options[:from][:channel] target.user = options[:from][:user] end @callback = callback end def call(event) channel = "channel: #{event.try(:channel).try(:name)}" element = "#{target_element}: #{event.try(target_element)}" Debug.log "Listen event call(#{channel} / #{element})" return unless valid?(event) return unless target?(event) Debug.log "Callback event call: #{pattern}" @callback.call(event) end private def target_element self.class.name.split('::').last.gsub(/Listener$/, '').underscore.to_sym end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
slappy-0.6.3 | lib/slappy/listeners/base.rb |
slappy-0.6.2 | lib/slappy/listeners/base.rb |
slappy-0.6.1 | lib/slappy/listeners/base.rb |
slappy-0.6.0 | lib/slappy/listeners/base.rb |