Sha256: 2a00e9d66941280284ef4cecc64c216689fe6c338aa6febbb7bcf130cdaa32a9

Contents?: true

Size: 1.31 KB

Versions: 11

Compression:

Stored size: 1.31 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

        def current_user
          Isomorfeus.current_user
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
isomorfeus-transport-1.0.0.zeta23 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta22 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta21 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta20 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta19 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta18 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta17 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta16 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta15 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta14 lib/lucid_channel/mixin.rb
isomorfeus-transport-1.0.0.zeta13 lib/lucid_channel/mixin.rb