module Roda::RodaPlugins::Base::RequestClassMethods

Class methods for RodaRequest

Attributes

match_pattern_cache[RW]

The cache to use for match patterns for this request class.

roda_class[RW]

Reference to the Roda class related to this request class.

Public Instance Methods

cached_matcher(obj) { || ... } click to toggle source

Return the cached pattern for the given object. If the object is not already cached, yield to get the basic pattern, and convert the basic pattern to a pattern that does not partial segments.

# File lib/roda.rb, line 368
def cached_matcher(obj)
  cache = @match_pattern_cache

  unless pattern = cache[obj]
    pattern = cache[obj] = consume_pattern(yield)
  end

  pattern
end
def_verb_method(mod, verb) click to toggle source

Define a verb method in the given that will yield to the match block if the request method matches and there are either no arguments or there is a successful terminal match on the arguments.

# File lib/roda.rb, line 381
        def def_verb_method(mod, verb)
          mod.class_eval(<<-END, __FILE__, __LINE__+1)
            def #{verb}(*args, &block)
              _verb(args, &block) if #{verb == :get ? :is_get : verb}?
            end
          END
        end
inspect() click to toggle source

Since RodaRequest is anonymously subclassed when Roda is subclassed, and then assigned to a constant of the Roda subclass, make inspect reflect the likely name for the class.

# File lib/roda.rb, line 392
def inspect
  "#{roda_class.inspect}::RodaRequest"
end

Private Instance Methods

consume_pattern(pattern) click to toggle source

The pattern to use for consuming, based on the given argument. The returned pattern requires the path starts with a string and does not match partial segments.

# File lib/roda.rb, line 401
def consume_pattern(pattern)
  /\A(\/(?:#{pattern}))(?=\/|\z)/
end