Sha256: 45ce2254a8f0af82c9ad2d38944b4d47ab2492485b362c9ce77369df82c8edd5

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

module Sinatra
  module RocketIO

    def rocketio=(options)
      RocketIO.options = options
    end

    def rocketio
      RocketIO.options
    end

    def self.default_options
      {
        :comet => [true, lambda{|v| [true, false].include? v }],
        :websocket => [true, lambda{|v| [true, false].include? v }]
      }
    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::RocketIO setting - \"#{k}\" is not valid key"
        else
          unless default_options[k][1].call(v)
            default = default_options[k][0]
            STDERR.puts "!! Sinatra::RocketIO 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

2 entries across 2 versions & 1 rubygems

Version Path
sinatra-rocketio-0.2.4 lib/sinatra-rocketio/options.rb
sinatra-rocketio-0.2.3 lib/sinatra-rocketio/options.rb