Sha256: da613cb5006e05055963f885683edb20c45b9d9c2874ab9571b4a3ab67eff14a

Contents?: true

Size: 1.94 KB

Versions: 4

Compression:

Stored size: 1.94 KB

Contents

require 'fake_sqs/api'
require 'fake_sqs/catch_errors'
require 'fake_sqs/collection_view'
require 'fake_sqs/error_response'
require 'fake_sqs/message'
require 'fake_sqs/queue'
require 'fake_sqs/queue_factory'
require 'fake_sqs/queues'
require 'fake_sqs/responder'
require 'fake_sqs/server'
require 'fake_sqs/version'
require 'fake_sqs/databases/file'
require 'fake_sqs/databases/memory'

module FakeSQS

  def self.to_rack(options)

    require 'fake_sqs/web_interface'
    app = FakeSQS::WebInterface

    if (log = options[:log])
      file = File.new(log, "a+")
      file.sync = true
      app.use Rack::CommonLogger, file
      app.set :log_file, file
      app.enable :logging
    end

    if options[:verbose]
      require 'fake_sqs/show_output'
      app.use FakeSQS::ShowOutput
      app.enable :logging
    end

    if options[:daemonize]
      require 'fake_sqs/daemonize'
      Daemonize.new(options).call
    end

    app.set :port, options[:port] if options[:port]
    app.set :bind, options[:host] if options[:host]
    app.set :server, options[:server] if options[:server]
    server = FakeSQS.server(port: options[:port], host: options[:host])
    app.set :api, FakeSQS.api(server: server, database: options[:database])
    app
  end

  def self.server(options = {})
    Server.new(options)
  end

  def self.api(options = {})
    db = database_for(options.fetch(:database) { ":memory:" })
    API.new(
      server: options.fetch(:server),
      queues: queues(db),
      responder: responder
    )
  end

  def self.queues(database)
    Queues.new(queue_factory: queue_factory, database: database)
  end

  def self.responder
    Responder.new
  end

  def self.queue_factory
    QueueFactory.new(message_factory: message_factory, queue: queue)
  end

  def self.message_factory
    Message
  end

  def self.queue
    Queue
  end

  def self.database_for(name)
    if name == ":memory:"
      MemoryDatabase.new
    else
      FileDatabase.new(name)
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fake_sqs-0.4.3 lib/fake_sqs.rb
fake_sqs-0.4.2 lib/fake_sqs.rb
fake_sqs-0.4.1 lib/fake_sqs.rb
fake_sqs-0.4.0 lib/fake_sqs.rb