Sha256: daf77bdb8e200e104612ff3e2ee1ec224d58d30f1f0d5a22246da93722c49ca9

Contents?: true

Size: 1.24 KB

Versions: 20

Compression:

Stored size: 1.24 KB

Contents

module LucidChannel
  module Mixin
    def self.included(base)

      if RUBY_ENGINE != 'opal'
        Isomorfeus.add_valid_channel_class(base) unless base == LucidChannel::Base
      end

      base.instance_exec do
        def process_message(channel, message = nil)
          if @message_processor
            if channel == self.name
              @message_processor.call(message)
            else
              @message_processor.call(channel, message)
            end
          else
            puts "#{self} received: #{channel} #{message}, but no 'on_message' block defined!"
          end
        end

        def on_message(&block)
          @message_processor = block
        end

        def send_message(channel, message = nil)
          unless message
            message = channel
            channel = self.name
          end
          Isomorfeus::Transport.send_notification(self, channel, message)
        end

        def subscribe(channel = nil)
          channel = channel ? channel : self.name
          Isomorfeus::Transport.subscribe(self, channel)
        end

        def unsubscribe(channel = nil)
          channel = channel ? channel : self.name
          Isomorfeus::Transport.unsubscribe(self, channel)
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
isomorfeus-transport-1.0.0.zeta12 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta11 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta10 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta9 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta8 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta7 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta6 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta5 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta4 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta3 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta2 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta1 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.epsilon4 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.epsilon3 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.epsilon2 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.epsilon1 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.delta12 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.delta11 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.delta10 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.delta9 lib/lucid_channel/mixin.rb