Sha256: c1e4eba79651691ae84345d34bb6d009abfb422725c94a74b03b0de477cddecd

Contents?: true

Size: 852 Bytes

Versions: 49

Compression:

Stored size: 852 Bytes

Contents

module Dynflow
  class Middleware::Register
    include Algebrick::TypeCheck

    attr_reader :rules

    def initialize
      @rules = Hash.new do |h, k|
        h[k] = { before:  [],
                 after:   [],
                 replace: [] }
      end
    end

    def use(middleware_class, options = {})
      unknown_options = options.keys - [:before, :after, :replace]
      if unknown_options.any?
        raise ArgumentError, "Unexpected options: #{unknown_options}"
      end
      @rules[middleware_class].merge!(options) do |key, old, new|
        old + Array(new)
      end
    end

    def do_not_use(middleware_class)
      use nil, :replace => middleware_class
    end

    def merge!(register)
      Type! register, Middleware::Register
      register.rules.each do |klass, rules|
        use(klass, rules)
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
dynflow-1.3.0 lib/dynflow/middleware/register.rb
dynflow-1.2.3 lib/dynflow/middleware/register.rb
dynflow-1.2.2 lib/dynflow/middleware/register.rb
dynflow-1.2.1 lib/dynflow/middleware/register.rb
dynflow-1.2.0 lib/dynflow/middleware/register.rb
dynflow-1.2.0.pre1 lib/dynflow/middleware/register.rb
dynflow-1.1.6 lib/dynflow/middleware/register.rb
dynflow-1.1.5 lib/dynflow/middleware/register.rb
dynflow-1.1.4 lib/dynflow/middleware/register.rb
dynflow-1.1.3 lib/dynflow/middleware/register.rb
dynflow-1.1.2 lib/dynflow/middleware/register.rb
dynflow-1.1.1 lib/dynflow/middleware/register.rb
dynflow-1.1.0 lib/dynflow/middleware/register.rb
dynflow-1.0.5 lib/dynflow/middleware/register.rb
dynflow-1.0.4 lib/dynflow/middleware/register.rb
dynflow-1.0.3 lib/dynflow/middleware/register.rb
dynflow-1.0.2 lib/dynflow/middleware/register.rb
dynflow-1.0.1 lib/dynflow/middleware/register.rb
dynflow-1.0.0 lib/dynflow/middleware/register.rb
dynflow-0.8.37 lib/dynflow/middleware/register.rb