Sha256: 215ca998dd268cba81a08ea6c1d437233e896e76e088105272c48a14f51ad415

Contents?: true

Size: 844 Bytes

Versions: 54

Compression:

Stored size: 844 Bytes

Contents

module Locomotive::Steam::Middlewares

  class StackProxy

    attr_reader :list, :operations

    def initialize(&block)
      @list = []
      instance_eval(&block) if block_given?
    end

    def use(*args, &block)
      @list << [args, block]
    end

    def insert_before(index, *args, &block)
      @list.insert(index_of(index), [args, block])
    end

    def insert_after(index, *args, &block)
      @list.insert(index_of(index) + 1, [args, block])
    end

    def delete(index)
      @list.delete_at(index_of(index))
    end

    alias :insert :insert_before

    def inject(builder)
      @list.each do |args|
        builder.use(*(args[0]), &args[1])
      end
    end

    def index_of(index)
      if index.is_a?(Integer)
        index
      else
        @list.index { |args| args[0][0] == index }
      end
    end

  end

end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.8.0.alpha1 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.7.1 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.7.0 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.6.1 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.6.0 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.6.0.rc1 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.6.0.beta1 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.5.3 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.5.2 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.5.1 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.5.0 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.5.0.rc1 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.5.0.rc0 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.5.0.beta3 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.5.0.beta2 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.5.0.beta1 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.4.1 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.4.0 lib/locomotive/steam/middlewares/stack_proxy.rb
locomotivecms_steam-1.4.0.rc2 lib/locomotive/steam/middlewares/stack_proxy.rb