From 9479dbea42fa1ffdd4f98a28cc610ae9cd6c9a72 Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Mon, 10 Oct 2011 21:45:07 -0700 Subject: [PATCH] Changed context that match blocks evaluate in Anything in a match block will be evaluated in a single context so that match blocks can pass data around. --- lib/wrack/irc/receiver.rb | 14 +++++++++----- lib/wrack/session.rb | 10 ++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/wrack/irc/receiver.rb b/lib/wrack/irc/receiver.rb index c839a19..1609488 100644 --- a/lib/wrack/irc/receiver.rb +++ b/lib/wrack/irc/receiver.rb @@ -2,15 +2,19 @@ class Wrack::IRC::Receiver include Wrack::IRC::Commands - def initialize(connection, &block) + def initialize(connection, context, options = {}, &block) + @context = context + @connection = connection + @restrictions = [] @matches = [] - @connection = connection + + restrict options instance_eval &block end - def receive(&block) - receiver = Wrack::IRC::Receiver.new(@connection, &block) + def receive(options = {}, &block) + receiver = Wrack::IRC::Receiver.new(@connection, @context, options, &block) @matches << receiver end @@ -57,7 +61,7 @@ def notify(msg) if match.is_a? Wrack::IRC::Receiver match.notify msg else - match.call(msg) + @context.instance_exec msg, &match end rescue => e $stderr.puts "Aborted while calling match!" diff --git a/lib/wrack/session.rb b/lib/wrack/session.rb index 4c018f4..045638f 100644 --- a/lib/wrack/session.rb +++ b/lib/wrack/session.rb @@ -1,7 +1,5 @@ -# The actual IRC implementation class. Pulls in the connection and IRC -# implementation details -# -# If you're looking for a complete bot, this should be the place +# Assembles the higher level components of an IRC connection on top of a raw +# socket. Manages callbacks and maintains the connection. require 'wrack' require 'wrack/irc' module Wrack @@ -33,8 +31,8 @@ def disconnect @connection.disconnect end - def receive(&block) - receiver = Wrack::IRC::Receiver.new(@connection, &block) + def receive(context, &block) + receiver = Wrack::IRC::Receiver.new(@connection, context, &block) @receivers << receiver end