Sha256: ccc765ce2a1444d47b370507d56eb0bf70b6223efbf0e2b7015f445458eda2bc

Contents?: true

Size: 1.1 KB

Versions: 25

Compression:

Stored size: 1.1 KB

Contents

module Msgr

  class Routes
    include Logging
    attr_reader :routes
    delegate :each, :empty?, :size, :any?, to: :@routes

    def initialize
      @routes = []
    end

    def configure(&block)
      blocks << block
      instance_eval &block
    end

    def files
      @files ||= []
    end

    def blocks
      @blocks ||= []
    end

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

    def <<(file)
      files << file
    end

    def reload
      routes.clear
      blocks.each { |block| instance_eval(&block) }
      files.uniq!
      files.each do |file|
        if File.exists? file
          load file
        else
          log(: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

25 entries across 25 versions & 1 rubygems

Version Path
msgr-0.14.1.1.b125 lib/msgr/routes.rb
msgr-0.14.1.1.b124 lib/msgr/routes.rb
msgr-0.14.1.1.b112 lib/msgr/routes.rb
msgr-0.14.1.1.b111 lib/msgr/routes.rb
msgr-0.14.1.1.b110 lib/msgr/routes.rb
msgr-0.14.1 lib/msgr/routes.rb
msgr-0.14.0 lib/msgr/routes.rb
msgr-0.13.0 lib/msgr/routes.rb
msgr-0.12.3 lib/msgr/routes.rb
msgr-0.12.2 lib/msgr/routes.rb
msgr-0.12.1 lib/msgr/routes.rb
msgr-0.12.0 lib/msgr/routes.rb
msgr-0.11.1 lib/msgr/routes.rb
msgr-0.11.0 lib/msgr/routes.rb
msgr-0.11.0.rc3 lib/msgr/routes.rb
msgr-0.11.0.rc2 lib/msgr/routes.rb
msgr-0.11.0.rc1 lib/msgr/routes.rb
msgr-0.10.2 lib/msgr/routes.rb
msgr-0.10.1 lib/msgr/routes.rb
msgr-0.10.0 lib/msgr/routes.rb