Sha256: f1908dc22ce26410ef1554388e25d65ba2b91b8fe51705f930633d492e57137d

Contents?: true

Size: 899 Bytes

Versions: 7

Compression:

Stored size: 899 Bytes

Contents

module Msgr

  class Routes
    attr_reader :routes
    delegate :each, to: :@routes

    def initialize
      @routes = []
    end

    def configure(&block)
      instance_eval &block
    end

    def files
      @files ||= []
    end

    def files=(files)
      @files = Array files
    end

    def reload
      routes.clear
      files.each do |file|
        if File.exists? file
          load file
        else
          Msgr.logger.warn "Routes file `#{file}` does not exists (anymore)."
        end
      end
    end

    def load(file)
      raise ArgumentError.new "File `#{file}` does not exists." unless File.exists? file
      instance_eval File.read file
    end

    def route(key, opts = {})
      routes.each do |route|
        if route.accept? key, opts
          route.add key
          return
        end
      end

      routes << Msgr::Route.new(key, opts)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
msgr-0.4.1 lib/msgr/routes.rb
msgr-0.4.0 lib/msgr/routes.rb
msgr-0.3.0 lib/msgr/routes.rb
msgr-0.2.1 lib/msgr/routes.rb
msgr-0.2.0 lib/msgr/routes.rb
msgr-0.1.1 lib/msgr/routes.rb
msgr-0.1.0 lib/msgr/routes.rb