Sha256: a52bf3bb6a9038bf03384fed1a49ac42663e321ba2cd06594607aaef0ff46e54

Contents?: true

Size: 875 Bytes

Versions: 8

Compression:

Stored size: 875 Bytes

Contents

require 'sitehub/middleware'
require 'sitehub/rules'

class SiteHub
  class Route
    include Middleware, Resolver, Rules, Equality

    attr_reader :id, :sitehub_cookie_name, :sitehub_cookie_path, :app

    def initialize(app, id:, sitehub_cookie_name:, sitehub_cookie_path: nil)
      @app = app
      @id = Identifier.new(id)
      @sitehub_cookie_name = sitehub_cookie_name
      @sitehub_cookie_path = sitehub_cookie_path
    end

    def call(env)
      request = env[REQUEST]
      @app.call(env).tap do |response|
        response.set_cookie(sitehub_cookie_name,
                            path: resolve_sitehub_cookie_path(request),
                            value: id)
      end
    end

    def resolve_sitehub_cookie_path(request)
      sitehub_cookie_path || request.path
    end

    def init
      @app = apply_middleware(@app)
      self
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sitehub-0.5.0.alpha12 lib/sitehub/middleware/route.rb
sitehub-0.5.0.alpha11 lib/sitehub/middleware/route.rb
sitehub-0.5.0.alpha10 lib/sitehub/middleware/route.rb
sitehub-0.5.0.alpha8 lib/sitehub/middleware/route.rb
sitehub-0.5.0.alpha7 lib/sitehub/middleware/route.rb
sitehub-0.5.0.alpha6 lib/sitehub/middleware/route.rb
sitehub-0.5.0.alpha5 lib/sitehub/middleware/route.rb
sitehub-0.5.0.alpha4 lib/sitehub/middleware/route.rb