class Praxis::RoutingConfig
Constants
- ABSOLUTE_PATH_REGEX
Attributes
Public Class Methods
Source
# File lib/praxis/routing_config.rb, line 7 def initialize(version: 'n/a', base: '', prefix: [], &block) @version = version @base = base @prefix_segments = Array(prefix) @route = nil instance_eval(&block) if block_given? end
Public Instance Methods
Source
# File lib/praxis/routing_config.rb, line 76 def add_route(verb, path, options = {}) path = prefix + path unless path =~ ABSOLUTE_PATH_REGEX prefixed_path = path.gsub('//', '/') path = (base + path).gsub('//', '/') pattern = Mustermann.new(path, **{ ignore_unknown_options: true }.merge(options)) @route = Route.new(verb, pattern, version, prefixed_path: prefixed_path, **options) end
Source
# File lib/praxis/routing_config.rb, line 70 def any(path, opts = {}) add_route 'ANY', path, opts end
Source
# File lib/praxis/routing_config.rb, line 62 def connect(path, opts = {}) add_route 'CONNECT', path, opts end
Source
# File lib/praxis/routing_config.rb, line 54 def delete(path, opts = {}) add_route 'DELETE', path, opts end
Source
# File lib/praxis/routing_config.rb, line 38 def get(path, opts = {}) add_route 'GET', path, opts end
Source
# File lib/praxis/routing_config.rb, line 42 def head(path, opts = {}) add_route 'HEAD', path, opts end
Source
# File lib/praxis/routing_config.rb, line 34 def options(path, opts = {}) add_route 'OPTIONS', path, opts end
Source
# File lib/praxis/routing_config.rb, line 66 def patch(path, opts = {}) add_route 'PATCH', path, opts end
Source
# File lib/praxis/routing_config.rb, line 46 def post(path, opts = {}) add_route 'POST', path, opts end
Source
# File lib/praxis/routing_config.rb, line 21 def prefix(prefix = nil) return @prefix_segments.join.gsub('//', '/') if prefix.nil? case prefix when '' @prefix_segments = [] when ABSOLUTE_PATH_REGEX @prefix_segments = Array(prefix[1..]) else @prefix_segments << prefix end end
Source
# File lib/praxis/routing_config.rb, line 50 def put(path, opts = {}) add_route 'PUT', path, opts end
Source
# File lib/praxis/routing_config.rb, line 58 def trace(path, opts = {}) add_route 'TRACE', path, opts end