Module: Hsdq::Shared

Included in:
Hsdq
Defined in:
lib/hsdq/shared.rb

Overview

The methods in this module are shared by different modules

Instance Method Summary collapse

Instance Method Details

#burst_key(spark) ⇒ String

Build the namespaced key for the spark and burst unique shared uid

Parameters:

  • spark (Hash)

Returns:

  • (String)

    the unique namespaced key

  • nil if spark or the spark_uid is nil



27
28
29
30
# File 'lib/hsdq/shared.rb', line 27

def burst_key(spark)
  return unless spark
  "#{spark[:type]}_#{spark[:spark_uid]}" if spark[:type] && spark[:spark_uid]
end

#hsdq_key(message_or_spark) ⇒ String

Build the namespaced key for the main hash storing the message history (collection of 'burst')

Parameters:

  • message_or_spark (Hash)

    a burst or a spark

Returns:

  • (String)

    the unique key for the main redis hash

  • nil if message_or_spark or the uid is nil



18
19
20
21
# File 'lib/hsdq/shared.rb', line 18

def hsdq_key(message_or_spark)
  return unless message_or_spark
  "hsdq_h_#{message_or_spark[:uid]}" if message_or_spark[:uid]
end

#placeholderObject



6
7
8
# File 'lib/hsdq/shared.rb', line 6

def placeholder
  "This is a placeholder, you must implement this method in your hsdq class"
end

#session_key(session_id) ⇒ String

Build the namespaced key for the main session hash

Parameters:

  • session_id (string)

    the unique uid for the session

Returns:

  • (String)

    the unique namespaced key

  • nil if session_id



36
37
38
39
# File 'lib/hsdq/shared.rb', line 36

def session_key(session_id)
  return unless session_id
  "hsdq_s_#{session_id}"
end

#valid_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/hsdq/shared.rb', line 10

def valid_type?(type)
  [:request, :ack, :callback, :feedback, :error].include? type.to_sym
end