module Deepstream::Helpers

Constants

DEFAULT_PATH
DEFAULT_PORT
SCHEME

Public Class Methods

default_options() click to toggle source
# File lib/deepstream/helpers.rb, line 34
def self.default_options
  {
    ack_timeout: nil,
    credentials: {},
    heartbeat_interval: nil,
    in_thread: true,
    verbose: false,
    debug: false,
    reinitialize_master: false
  }
end
message_data(*args, **kwargs) click to toggle source
# File lib/deepstream/helpers.rb, line 54
def self.message_data(*args, **kwargs)
  kwargs = kwargs.empty? ? nil : kwargs
  if args.empty?
    kwargs
  else
    (args << kwargs).compact.instance_eval { one? ? first : self }
  end
end
to_deepstream_type(value) click to toggle source
# File lib/deepstream/helpers.rb, line 9
def self.to_deepstream_type(value)
  case value
  when Array then "O#{value.to_json}"
  when Hash then "O#{value.to_json}"
  when String then "S#{value}"
  when Numeric then "N#{value}"
  when TrueClass then 'T'
  when FalseClass then 'F'
  when NilClass then 'L'
  end
end
to_type(payload) click to toggle source
# File lib/deepstream/helpers.rb, line 21
def self.to_type(payload)
  case payload[0]
  when 'O' then JSON.parse(payload[1..-1])
  when '{' then JSON.parse(payload)
  when 'S' then payload[1..-1]
  when 'N' then payload[1..-1].to_f
  when 'T' then true
  when 'F' then false
  when 'L' then nil
  else JSON.parse(payload)
  end
end
url(url) click to toggle source
# File lib/deepstream/helpers.rb, line 46
def self.url(url)
  url.tap do |url|
    url.prepend(SCHEME) unless url.start_with?(/ws(s|)\:\/\//)
    url.concat(":#{DEFAULT_PORT}") unless url[/\:\d+/]
    url.concat("/#{DEFAULT_PATH}") unless url[/:\d+\/\S+$/]
  end
end