class PusherFake::Configuration
Configuration
class.
Attributes
@return [String] The Pusher Applicaiton ID. (Defaults to PUSHER_APP_ID
.)
@return [Boolean] Disable the client statistics. (Defaults to true
.)
@return [String] The Pusher API key. (Defaults to PUSHER_API_KEY
.)
@return [IO] An IO instance for verbose logging.
@return [String] The Pusher API token. (Defaults to PUSHER_API_SECRET
.)
Options for the socket server. See EventMachine::WebSocket.start
.
@return [Hash] Options for the socket server.
@return [Boolean] Enable verbose logging.
Options for the web server. See Thin::Server
for options.
@return [Hash] Options for the web server.
@return [Array] An array of webhook URLs. (Defaults to []
.)
Public Class Methods
Instantiated from {PusherFake.configuration}. Sets the defaults.
# File lib/pusher-fake/configuration.rb, line 38 def initialize reset! end
Public Instance Methods
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
# 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
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
# 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
# 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