Sha256: 697f9abeadcfeec6e0dfb0ffdb65864f63ec184fae199b1e6af9b3b775247953

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

module Sinatra
  module CometIO

    def cometio=(options)
      CometIO.options = options
    end

    def cometio
      CometIO.options
    end

    def self.default_options
      {
        :timeout => [120, lambda{|v| v.kind_of? Fixnum and v >= 20 }],
        :post_interval => [1, lambda{|v| [Fixnum, Float].include? v.class and v >= 1 }],
        :allow_crossdomain => [false, 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::CometIO setting - \"#{k}\" is not valid key"
        else
          unless default_options[k][1].call(v)
            default = default_options[k][0]
            STDERR.puts "!! Sinatra::CometIO 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

4 entries across 4 versions & 1 rubygems

Version Path
sinatra-cometio-0.6.0 lib/sinatra-cometio/options.rb
sinatra-cometio-0.5.9 lib/sinatra-cometio/options.rb
sinatra-cometio-0.5.8 lib/sinatra-cometio/options.rb
sinatra-cometio-0.5.7 lib/sinatra-cometio/options.rb