Sha256: 6814ded0d71fe2bd1e7b5ae87959157080c27da14aae9d11aae909346c53fae0

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

# frozen-string-literal: true

require 'httparty'

using Rodbot::Refinements

module Rodbot
  module Rack

    class << self

      # Default +config.ru+
      #
      # In case you wish to do things differently, just copy the contents of
      # this method into your +config.ru+ file and tweak it.
      def boot(rack)
        loader = Zeitwerk::Loader.new
        loader.logger = Rodbot::Log.logger('loader')
        loader.push_dir(Rodbot.env.root.join('lib'))
        loader.push_dir(Rodbot.env.root.join('app'))

        if Rodbot.env.development? || Rodbot.env.test?
          loader.enable_reloading
          loader.setup
          rack.run ->(env) do
            loader.reload
            App.call(env)
          end
        else
          loader.setup
          Zeitwerk::Loader.eager_load_all
          rack.run App.freeze.app
        end
      end

      # Send request to the app service
      #
      # @param path [String] path e.g. +/help+
      # @param query [Hash] query hash e.g. +{ search: 'foobar' }+
      # @param method [Symbol, String] HTTP method
      # @param timeout [Integer] max seconds to wait for response
      # @return [HTTParty::Response]
      def request(path, query: {}, method: :get, timeout: 10)
        HTTParty.send(method, Rodbot::Services::App.url.uri_concat(path), query: query, timeout: timeout)
      end

    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rodbot-0.3.1 lib/rodbot/rack.rb
rodbot-0.3.0 lib/rodbot/rack.rb
rodbot-0.2.0 lib/rodbot/rack.rb
rodbot-0.1.1 lib/rodbot/rack.rb
rodbot-0.1.0 lib/rodbot/rack.rb