Sha256: b22c3d9f27767cd9bd22cec99138bca2518e0e3e8602e8a0907507532cf67d0f

Contents?: true

Size: 992 Bytes

Versions: 1

Compression:

Stored size: 992 Bytes

Contents

require "seteable"
require "syro"

class Tynn < Syro::Deck
  include Seteable

  def self.define(&block)
    @syro = Syro.new(self, &block)
  end

  def self.use(_middleware, *args, &block)
    middleware << proc { |app| _middleware.new(app, *args, &block) }
  end

  def self.call(env) # :nodoc:
    return to_app.call(env)
  end

  def self.to_app # :nodoc:
    fail("Missing application handler. Try #{ self }.define") unless @syro

    if middleware.empty?
      return @syro
    else
      return middleware.reverse.inject(@syro) { |a, m| m.call(a) }
    end
  end

  def self.middleware # :nodoc:
    return @middleware ||= []
  end

  def self.reset! # :nodoc:
    @syro = nil
    @middleware = []
  end

  def self.helpers(helper, *args, &block)
    self.include(helper)

    if defined?(helper::ClassMethods)
      self.extend(helper::ClassMethods)
    end

    if helper.respond_to?(:setup)
      helper.setup(self, *args, &block)
    end
  end
end

require_relative "tynn/version"

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tynn-0.0.4 lib/tynn.rb