Sha256: 0d2eea17be811783169104370cef916d6a092edfe884d0b84c5d279d15875974

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

require 'logger'
require 'sitehub/core'
require 'active_support/cache'

class SiteHub
  class Builder
    include Middleware
    extend GetterSetterMethods

    attr_reader :core
    getter_setters :access_logger, :error_logger, :config_server

    def force_ssl(except: [])
      @force_ssl = true
      @ssl_exclusions = except
    end

    def initialize(&block)
      @core = Core.new
      instance_eval(&block) if block
    end

    def build
      add_default_middleware
      use ConfigLoader, config_server if config_server
      apply_middleware(core.build)
    end

    def add_default_middleware
      use Rack::SslEnforcer, except: @ssl_exclusions if @force_ssl
      use Rack::FiberPool
      use Middleware::Logging::ErrorLogger, error_logger || ::Logger.new(STDERR)
      use Middleware::Logging::AccessLogger, access_logger || ::Logger.new(STDOUT)
      use Middleware::ErrorHandling
      use Middleware::TransactionId
    end

    def respond_to?(method)
      super || core.respond_to?(method)
    end

    def method_missing(method, *args, &block)
      core.send(method, *args, &block)
    rescue NoMethodError
      super
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sitehub-0.5.0.alpha7 lib/sitehub/builder.rb
sitehub-0.5.0.alpha6 lib/sitehub/builder.rb
sitehub-0.5.0.alpha5 lib/sitehub/builder.rb
sitehub-0.5.0.alpha4 lib/sitehub/builder.rb
sitehub-0.5.0.alpha3 lib/sitehub/builder.rb
sitehub-0.5.0.alpha2 lib/sitehub/builder.rb