class Praxis::RoutingConfig
Constants
- ABSOLUTE_PATH_REGEX
Attributes
base[R]
route[R]
version[R]
Public Class Methods
new(version: 'n/a', base: '', prefix: [], &block)
click to toggle 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
add_route(verb, path, options = {})
click to toggle 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
any(path, opts = {})
click to toggle source
# File lib/praxis/routing_config.rb, line 70 def any(path, opts = {}) add_route 'ANY', path, opts end
clear!()
click to toggle source
# File lib/praxis/routing_config.rb, line 17 def clear! @prefix_segments = [] end
connect(path, opts = {})
click to toggle source
# File lib/praxis/routing_config.rb, line 62 def connect(path, opts = {}) add_route 'CONNECT', path, opts end
delete(path, opts = {})
click to toggle source
# File lib/praxis/routing_config.rb, line 54 def delete(path, opts = {}) add_route 'DELETE', path, opts end
get(path, opts = {})
click to toggle source
# File lib/praxis/routing_config.rb, line 38 def get(path, opts = {}) add_route 'GET', path, opts end
head(path, opts = {})
click to toggle source
# File lib/praxis/routing_config.rb, line 42 def head(path, opts = {}) add_route 'HEAD', path, opts end
options(path, opts = {})
click to toggle source
# File lib/praxis/routing_config.rb, line 34 def options(path, opts = {}) add_route 'OPTIONS', path, opts end
patch(path, opts = {})
click to toggle source
# File lib/praxis/routing_config.rb, line 66 def patch(path, opts = {}) add_route 'PATCH', path, opts end
post(path, opts = {})
click to toggle source
# File lib/praxis/routing_config.rb, line 46 def post(path, opts = {}) add_route 'POST', path, opts end
prefix(prefix = nil)
click to toggle 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
put(path, opts = {})
click to toggle source
# File lib/praxis/routing_config.rb, line 50 def put(path, opts = {}) add_route 'PUT', path, opts end
trace(path, opts = {})
click to toggle source
# File lib/praxis/routing_config.rb, line 58 def trace(path, opts = {}) add_route 'TRACE', path, opts end