Module: ActivePubsub::Publishable::ClassMethods

Defined in:
lib/active_pubsub/publishable.rb

Instance Method Summary collapse

Instance Method Details

#exchange_keyObject



49
50
51
52
53
54
# File 'lib/active_pubsub/publishable.rb', line 49

def exchange_key
  [
    try(:exchange_prefix) { ::ActivePubsub.config.try(:publish_as) },
    name.demodulize.underscore
  ].flatten.compact.join(".")
end

#publish_as(prefix) ⇒ Object

this is the publishing service namespace which will be used to build exchange name



58
59
60
61
62
63
64
# File 'lib/active_pubsub/publishable.rb', line 58

def publish_as(prefix)
  self.exchange_prefix = prefix

  ::ActivePubsub::Publisher.start unless ::ActivePubsub::Publisher.started

  ::ActivePubsub.publisher.register_exchange(exchange_key)
end

#publishable_actions(*actions) ⇒ Object

todo: make publishable actions filterable/appendable



67
68
69
# File 'lib/active_pubsub/publishable.rb', line 67

def publishable_actions(*actions)
  @publishable_actions = actions
end

#resource_routing_keysObject



75
76
77
# File 'lib/active_pubsub/publishable.rb', line 75

def resource_routing_keys
  [try(:exchange_prefix), name.demodulize.underscore].flatten.compact
end

#routing_keyObject



71
72
73
# File 'lib/active_pubsub/publishable.rb', line 71

def routing_key
  resource_routing_keys.join(".")
end