Sha256: 4220172b6893039f3d20fde2570201cc9b5aa53a6dc98dac9eacd8cd1a1427c0

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

#-  Ruby source code

#-  qm.rb ~~
#                                                       ~~ (c) SRW, 12 Apr 2013
#                                                   ~~ last updated 04 Aug 2014

module QM

    def self::launch_client(options = {})
      # This function needs documentation.
        require 'client'
        return QMachineClient.new(options)
    end

    def self::launch_service(options = {})
      # This function creates, configures, and launches a fresh Sinatra app
      # that inherits from the original "teaching version".
        require 'defs-mongo'
        require 'service'
        app = Sinatra.new(QMachineService) do
            register Sinatra::MongoConnect
            configure do
                convert = lambda do |x|
                  # This converts all keys in a hash to symbols recursively.
                    if (x.is_a?(Hash)) then
                        x = x.inject({}) do |memo, (k, v)|
                            memo[k.to_sym] = convert.call(v)
                            memo
                        end
                    end
                    return x
                end
                options = convert.call(options)
                set options
                if (settings.persistent_storage.has_key?(:mongo)) then
                    helpers Sinatra::MongoAPIDefs
                    mongo_api_connect
                end
                if (settings.trafficlog_storage.has_key?(:mongo)) then
                    helpers Sinatra::MongoLogDefs
                    mongo_log_connect
                    after do
                        log_to_db unless response.status == 444
                    end
                end
            end
        end
        return app.run!
    end

end

#-  vim:set syntax=ruby:

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
qm-1.1.15 lib/qm.rb
qm-1.1.14 lib/qm.rb