Module: Roda::RodaPlugins::Base::RequestClassMethods

Defined in:
lib/roda.rb

Overview

Class methods for RodaRequest

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#match_pattern_cacheObject

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



367
368
369
# File 'lib/roda.rb', line 367

def match_pattern_cache
  @match_pattern_cache
end

#roda_classObject

Reference to the Roda class related to this request class.



364
365
366
# File 'lib/roda.rb', line 364

def roda_class
  @roda_class
end

Instance Method Details

#cached_matcher(obj) ⇒ Object

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.



372
373
374
375
376
377
378
379
380
# File 'lib/roda.rb', line 372

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) ⇒ Object

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.



385
386
387
388
389
390
391
# File 'lib/roda.rb', line 385

def def_verb_method(mod, verb)
  mod.class_eval("    def \#{verb}(*args, &block)\n      _verb(args, &block) if \#{verb == :get ? :is_get : verb}?\n    end\n  END\nend\n", __FILE__, __LINE__+1)

#inspectObject

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.



396
397
398
# File 'lib/roda.rb', line 396

def inspect
  "#{roda_class.inspect}::RodaRequest"
end