Sha256: ab6b8e43f0edd41f8cbe648fec7c0e1aed3534af49c47adf3d5cb5898b481502

Contents?: true

Size: 1.23 KB

Versions: 13

Compression:

Stored size: 1.23 KB

Contents

module Sinatra
  module WebSocketIO

    def websocketio=(options)
      WebSocketIO.options = options
    end

    def websocketio
      WebSocketIO.options
    end

    def self.default_options
      {
        :port => [(ENV['WS_PORT']||9000).to_i, lambda{|v| v.kind_of? Fixnum and v > 0 }]
      }
    end

    def self.options
      @@options ||= (
                     opts = {}
                     default_options.each do |k,v|
                       opts[k] = v[0]
                     end
                     opts
                     )
    end

    def self.options=(opts)
      @@options = {}
      opts.each do |k,v|
        k = k.to_sym
        unless default_options.include? k
          STDERR.puts "!! Sinatra::WebSocketIO setting - \"#{k}\" is not valid key"
        else
          unless default_options[k][1].call(v)
            default = default_options[k][0]
            STDERR.puts "!! Sinatra::WebSocketIO setting - \"#{k} => #{v}\" is not valid. set default \"#{k} => #{default}\""
            @@options[k] = default
          else
            @@options[k] = v
          end
        end
      end
      default_options.each do |k, v|
        @@options[k] = v[0] unless @@options.include? k
      end
      @@options
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
sinatra-websocketio-0.4.1 lib/sinatra-websocketio/options.rb
sinatra-websocketio-0.4.0 lib/sinatra-websocketio/options.rb
sinatra-websocketio-0.3.9 lib/sinatra-websocketio/options.rb
sinatra-websocketio-0.3.7 lib/sinatra-websocketio/options.rb
sinatra-websocketio-0.3.6 lib/sinatra-websocketio/options.rb
sinatra-websocketio-0.3.5 lib/sinatra-websocketio/options.rb
sinatra-websocketio-0.3.4 lib/sinatra-websocketio/options.rb
sinatra-websocketio-0.3.3 lib/sinatra-websocketio/options.rb
sinatra-websocketio-0.3.2 lib/sinatra-websocketio/options.rb
sinatra-websocketio-0.3.1 lib/sinatra-websocketio/options.rb
sinatra-websocketio-0.3.0 lib/sinatra-websocketio/options.rb
sinatra-websocketio-0.2.9 lib/sinatra-websocketio/options.rb
sinatra-websocketio-0.2.8 lib/sinatra-websocketio/options.rb