Sha256: 84e5ac89ce0f6a01a82c621c191d3d7d71a74e22316d4b403320e219df6407eb

Contents?: true

Size: 762 Bytes

Versions: 26

Compression:

Stored size: 762 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 merge!(register)
      Type! register, Middleware::Register
      register.rules.each do |klass, rules|
        use(klass, rules)
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
dynflow-0.8.7 lib/dynflow/middleware/register.rb
dynflow-0.8.6 lib/dynflow/middleware/register.rb
dynflow-0.8.5 lib/dynflow/middleware/register.rb
dynflow-0.8.4 lib/dynflow/middleware/register.rb
dynflow-0.8.3 lib/dynflow/middleware/register.rb
dynflow-0.8.2 lib/dynflow/middleware/register.rb
dynflow-0.8.1 lib/dynflow/middleware/register.rb
dynflow-0.8.0 lib/dynflow/middleware/register.rb
dynflow-0.7.9 lib/dynflow/middleware/register.rb
dynflow-0.7.8 lib/dynflow/middleware/register.rb
dynflow-0.7.7 lib/dynflow/middleware/register.rb
dynflow-0.7.6 lib/dynflow/middleware/register.rb
dynflow-0.7.5 lib/dynflow/middleware/register.rb
dynflow-0.7.4 lib/dynflow/middleware/register.rb
dynflow-0.7.3 lib/dynflow/middleware/register.rb
dynflow-0.7.2 lib/dynflow/middleware/register.rb
dynflow-0.7.1 lib/dynflow/middleware/register.rb
dynflow-0.7.0 lib/dynflow/middleware/register.rb
dynflow-0.6.2 lib/dynflow/middleware/register.rb
dynflow-0.6.1 lib/dynflow/middleware/register.rb