Sha256: 3d6541b28f4530566542b377fea853d5383dae9f4ab06f554f01b647401681f9

Contents?: true

Size: 978 Bytes

Versions: 15

Compression:

Stored size: 978 Bytes

Contents

module Jeanine
  module Routing
    module Evaluation
      def route_eval
        route = find_route
        if route
          result = instance_eval(&route[:block])
          @response.write(result)
        else
          @response.status = 404
        end
        @response.complete!
      end

      private

      def find_route
        matches = nil
        route = Jeanine.router[@request.request_method.to_sym].detect do |r|
          matches = r[:compiled_path].match(@request.path_info)
          !matches.nil?
        end

        return nil if route.nil?
        return route if route && route[:params].empty?

        index = 0
        while index < matches.captures.size
          param = route[:params][index]
          @request.params[param] = matches.captures[index]
          if index == matches.captures.size
            @request.params[param].gsub!(@request.format)
          end
          index += 1
        end

        route
      end

    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
jeanine-0.8.1 lib/jeanine/routing/evaluation.rb
jeanine-0.8 lib/jeanine/routing/evaluation.rb
jeanine-0.7.8 lib/jeanine/routing/evaluation.rb
jeanine-0.7.7 lib/jeanine/routing/evaluation.rb
jeanine-0.7.6 lib/jeanine/routing/evaluation.rb
jeanine-0.7.5 lib/jeanine/routing/evaluation.rb
jeanine-0.7.4 lib/jeanine/routing/evaluation.rb
jeanine-0.7.3.2 lib/jeanine/routing/evaluation.rb
jeanine-0.7.3.1 lib/jeanine/routing/evaluation.rb
jeanine-0.7.3 lib/jeanine/routing/evaluation.rb
jeanine-0.7.2 lib/jeanine/routing/evaluation.rb
jeanine-0.7.1 lib/jeanine/routing/evaluation.rb
jeanine-0.7.0 lib/jeanine/routing/evaluation.rb
jeanine-0.6.0 lib/jeanine/routing/evaluation.rb
jeanine-0.5.0 lib/jeanine/routing/evaluation.rb