Sha256: 1a031b5b949a3048578ef6298c76aa45db7a49aa6457d813c4967296fcca67bf

Contents?: true

Size: 941 Bytes

Versions: 1

Compression:

Stored size: 941 Bytes

Contents

module EngineRouter
  class Routes

    def initialize (engine)
      @engine = engine
      clear_routes
    end

    def engine
      @engine
    end

    def prepend &block
      unless prepend_routes.include?(block)
        @prepend_routes << block
      end
    end

    def append &block
      unless append_routes.include?(block)
        @append_routes << block
      end
    end

    def draw &block
      prepend_routes.each { |r| eval_block(&r) }
      eval_block(&block) if block_given?
      append_routes.each { |r| eval_block(&r) }
      # Clear out routes so that they aren't drawn twice.
      clear_routes
    end

    def eval_block(&block)
      engine.routes.send(:eval_block,block)
    end

    def clear_routes
      @prepend_routes = []
      @append_routes = []
    end

    private

    def prepend_routes
      @prepend_routes ||= []
    end

    def append_routes
      @append_routes ||= []
    end



  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
engine_router-0.1.0 lib/engine_router/routes.rb