Sha256: f12a89157ed1fa37a17e99f9d513ae603188a0eee7fe01a34b76e212fd98b711

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

require_relative 'core_ext'
require_relative 'monkey_patches'
require_relative 'liquid'
require_relative 'services'
require_relative 'middlewares'

module Locomotive::Steam
  class Server

    attr_reader :reader, :app, :options

    def initialize(reader, options = {})
      @reader   = reader
      @options  = options

      stack     = Middlewares::Stack.new(options)
      @app      = stack.create
    end

    def call(env)
      dup._call(env) # thread-safe purpose
    end

    def _call(env)
      set_request(env)

      set_mounting_point(env)

      set_services(env)

      @app.call(env)
    end

    protected

    def set_request(env)
      @request = Rack::Request.new(env)
      env['steam.request'] = @request
    end

    def set_mounting_point(env)
      # one single mounting point per site
      @mounting_point = @reader.new_mounting_point(@request.host)
      env['steam.mounting_point'] = @reader.mounting_point
    end

    def set_services(env)
      env['steam.services'] = {
        dragonfly:      Locomotive::Steam::Services::Dragonfly.new(@mounting_point.path),
        markdown:       Locomotive::Steam::Services::Markdown.new,
        external_api:   Locomotive::Steam::Services::ExternalAPI.new
      }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
locomotivecms_steam-0.1.1 lib/locomotive/steam/server.rb