class PusherFake::Configuration

Configuration class.

Attributes

app_id[R]

@return [String] The Pusher Applicaiton ID. (Defaults to PUSHER_APP_ID.)

disable_stats[RW]

@return [Boolean] Disable the client statistics. (Defaults to true.)

key[RW]

@return [String] The Pusher API key. (Defaults to PUSHER_API_KEY.)

logger[RW]

@return [IO] An IO instance for verbose logging.

secret[RW]

@return [String] The Pusher API token. (Defaults to PUSHER_API_SECRET.)

socket_options[RW]

Options for the socket server. See EventMachine::WebSocket.start.

@return [Hash] Options for the socket server.

verbose[RW]

@return [Boolean] Enable verbose logging.

web_options[RW]

Options for the web server. See Thin::Server for options.

@return [Hash] Options for the web server.

webhooks[RW]

@return [Array] An array of webhook URLs. (Defaults to [].)

Public Class Methods

new() click to toggle source

Instantiated from {PusherFake.configuration}. Sets the defaults.

# File lib/pusher-fake/configuration.rb, line 38
def initialize
  reset!
end

Public Instance Methods

app_id=(id) click to toggle source

Assign the application ID, ensuring it’s a string.

@params [Integer|String] id The application ID.

# File lib/pusher-fake/configuration.rb, line 45
def app_id=(id)
  @app_id = id.to_s
end
reset!() click to toggle source
# File lib/pusher-fake/configuration.rb, line 49
def reset!
  self.app_id   = "PUSHER_APP_ID"
  self.key      = "PUSHER_API_KEY"
  self.logger   = standard_out_io
  self.secret   = "PUSHER_API_SECRET"
  self.verbose  = false
  self.webhooks = []

  self.disable_stats  = true
  self.socket_options = { host: "127.0.0.1", port: available_port }
  self.web_options    = { host: "127.0.0.1", port: available_port }
end
to_options(options = {}) click to toggle source

Convert the configuration to a hash sutiable for Pusher JS options.

@param [Hash] options Custom options for Pusher client.

# File lib/pusher-fake/configuration.rb, line 65
def to_options(options = {})
  options.merge(
    wsHost:       socket_options[:host],
    wsPort:       socket_options[:port],
    cluster:      "us-east-1",
    forceTLS:     false,
    disableStats: disable_stats
  )
end

Private Instance Methods

available_port() click to toggle source
# File lib/pusher-fake/configuration.rb, line 77
def available_port
  socket = Socket.new(:INET, :STREAM, 0)
  socket.bind(Addrinfo.tcp("127.0.0.1", 0))
  socket.local_address.ip_port.tap do
    socket.close
  end
end
standard_out_io() click to toggle source
# File lib/pusher-fake/configuration.rb, line 85
def standard_out_io
  if $stdout.respond_to?(:to_io)
    $stdout.to_io
  else
    $stdout
  end
end