Sha256: abf8dbc754bd9036133596fbf0f5a6ae028c4d806215f009881df31e85e8136c

Contents?: true

Size: 900 Bytes

Versions: 1

Compression:

Stored size: 900 Bytes

Contents

module Peictt
  module Builder
    class Router
      def initialize
        @routes = []
        @placeholders = []
      end

      def draw(&block)
        instance_eval(&block)
      end

      def all
        @routes
      end

      def root(arg)
        url = "/"
        route = Peictt::Http::GET.new url, to: arg
        @routes << route
        route
      end

      def method_missing(name, url, args = {})
        verb = name.to_s.upcase
        verb_class = Object.const_get "Peictt::Http::#{verb}"
        route = verb_class.new url, args
        @routes << route unless route_exists? route
        route
      end

      def route_exists?(route)
        @routes.each do |r|
          if r.url == route.url
            return true
          end
        end
        false
      end

      def respond_to_missing?(type, include_private = false)
        super
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
peictt-0.1.1 lib/peictt/builder/router.rb