Class: Qs::Event

Inherits:
Message show all
Defined in:
lib/qs/event.rb

Defined Under Namespace

Modules: RouteName, SubscribersRedisKey

Constant Summary collapse

PAYLOAD_TYPE =
'event'

Instance Attribute Summary collapse

Attributes inherited from Message

#params, #payload_type

Instance Method Summary collapse

Methods inherited from Message

#route_id

Constructor Details

#initialize(channel, name, options = nil) ⇒ Event

Returns a new instance of Event.



11
12
13
14
15
16
17
18
19
20
# File 'lib/qs/event.rb', line 11

def initialize(channel, name, options = nil)
  options ||= {}
  options[:params] ||= {}
  validate!(channel, name, options[:params])
  @channel      = channel
  @name         = name
  @publisher    = options[:publisher]
  @published_at = options[:published_at] || Time.now
  super(PAYLOAD_TYPE, options)
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



9
10
11
# File 'lib/qs/event.rb', line 9

def channel
  @channel
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/qs/event.rb', line 9

def name
  @name
end

#published_atObject (readonly)

Returns the value of attribute published_at.



9
10
11
# File 'lib/qs/event.rb', line 9

def published_at
  @published_at
end

#publisherObject (readonly)

Returns the value of attribute publisher.



9
10
11
# File 'lib/qs/event.rb', line 9

def publisher
  @publisher
end

Instance Method Details

#==(other) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/qs/event.rb', line 40

def ==(other)
  if other.kind_of?(self.class)
    self.payload_type == other.payload_type &&
    self.channel      == other.channel      &&
    self.name         == other.name         &&
    self.params       == other.params       &&
    self.publisher    == other.publisher    &&
    self.published_at == other.published_at
  else
    super
  end
end

#inspectObject



30
31
32
33
34
35
36
37
38
# File 'lib/qs/event.rb', line 30

def inspect
  reference = '0x0%x' % (self.object_id << 1)
  "#<#{self.class}:#{reference} " \
  "@channel=#{self.channel.inspect} " \
  "@name=#{self.name.inspect} " \
  "@params=#{self.params.inspect} " \
  "@publisher=#{self.publisher.inspect} " \
  "@published_at=#{self.published_at.inspect}>"
end

#route_nameObject



22
23
24
# File 'lib/qs/event.rb', line 22

def route_name
  @route_name ||= Event::RouteName.new(self.channel, self.name)
end

#subscribers_redis_keyObject



26
27
28
# File 'lib/qs/event.rb', line 26

def subscribers_redis_key
  @subscribers_redis_key ||= SubscribersRedisKey.new(self.route_name)
end