Sha256: e95bc722e57b10f4ed2cec0f2328d56b6c4415dd8d13f7c2927efb4df837f314

Contents?: true

Size: 774 Bytes

Versions: 10

Compression:

Stored size: 774 Bytes

Contents

module Surrounded
  module Context
    module Forwarding
      def forward_trigger(receiver, message, alternate=message)
        raise(ArgumentError, %{you may not forward '%{m}`} % {m: message}) if ['__id__','__send__'].include?(message.to_s)
        trigger alternate do |*args, &block|
          self.send(receiver).public_send(message,*args, &block)
        end
      end
      
      def forward_triggers(receiver, *messages)
        messages.each do |message|
          forward_trigger(receiver, message)
        end
      end
      
      def forwarding(hash)
        hash.each { |messages, receiver|
          forward_triggers(receiver, *messages)
        }
      end
      
      alias forward forward_trigger
      alias forwards forward_triggers
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
surrounded-1.1.0 lib/surrounded/context/forwarding.rb
surrounded-1.0.0 lib/surrounded/context/forwarding.rb
surrounded-0.9.11 lib/surrounded/context/forwarding.rb
surrounded-0.9.10 lib/surrounded/context/forwarding.rb
surrounded-0.9.9 lib/surrounded/context/forwarding.rb
surrounded-0.9.8 lib/surrounded/context/forwarding.rb
surrounded-0.9.7 lib/surrounded/context/forwarding.rb
surrounded-0.9.6 lib/surrounded/context/forwarding.rb
surrounded-0.9.5 lib/surrounded/context/forwarding.rb
surrounded-0.9.4 lib/surrounded/context/forwarding.rb