class Myxi::Exchange
Constants
- EXCHANGES
Attributes
exchange_name[RW]
key_type[RW]
model_name[RW]
Public Class Methods
add(exchange_name, *args, &block)
click to toggle source
# File lib/myxi/exchange.rb, line 10 def self.add(exchange_name, *args, &block) EXCHANGES[exchange_name.to_sym] = self.new(exchange_name, *args, &block) end
declare_all()
click to toggle source
# File lib/myxi/exchange.rb, line 14 def self.declare_all EXCHANGES.keys.each do |exch| Myxi.channel.direct(exch.to_s) end end
new(exchange_name, model_name = nil, &block)
click to toggle source
# File lib/myxi/exchange.rb, line 20 def initialize(exchange_name, model_name = nil, &block) @exchange_name = exchange_name.to_sym @model_name = model_name @permission_block = block end
Public Instance Methods
can_subscribe?(routing_key, user)
click to toggle source
# File lib/myxi/exchange.rb, line 42 def can_subscribe?(routing_key, user) if has_model? @permission_block.call(model_instance(routing_key), user) else @permission_block.call(routing_key, user) end end
has_model?()
click to toggle source
# File lib/myxi/exchange.rb, line 26 def has_model? !!@model_name end
model()
click to toggle source
# File lib/myxi/exchange.rb, line 30 def model has_model? && model_name.constantize end
model_instance(id)
click to toggle source
# File lib/myxi/exchange.rb, line 38 def model_instance(id) has_model? ? model.where(key_type.to_sym => id.to_i).first : nil end