class Praxis::RoutingConfig
Constants
- ABSOLUTE_PATH_REGEX
Attributes
base[R]
routes[R]
version[R]
Public Class Methods
new(version:'n/a'.freeze, base: '', prefix:[], &block)
click to toggle source
# File lib/praxis/routing_config.rb, line 8 def initialize(version:'n/a'.freeze, base: '', prefix:[], &block) @version = version @base = base @prefix_segments = Array(prefix) @routes = [] if block_given? instance_eval(&block) end end
Public Instance Methods
add_route(verb, path, options={})
click to toggle source
# File lib/praxis/routing_config.rb, line 50 def add_route(verb, path, options={}) unless path =~ ABSOLUTE_PATH_REGEX path = prefix + path end prefixed_path = path.gsub('//','/') path = (base + path).gsub('//','/') # Reject our own options route_name = options.delete(:name); pattern = Mustermann.new(path, {ignore_unknown_options: true}.merge( options )) route = Route.new(verb, pattern, version, name: route_name, prefixed_path: prefixed_path, **options) @routes << route route end
any(path, opts={})
click to toggle source
# File lib/praxis/routing_config.rb, line 46 def any(path, opts={}) add_route 'ANY', path, opts end
clear!()
click to toggle source
# File lib/praxis/routing_config.rb, line 20 def clear! @prefix_segments = [] end
connect(path, opts={})
click to toggle source
# File lib/praxis/routing_config.rb, line 44 def connect(path, opts={}) add_route 'CONNECT', path, opts end
delete(path, opts={})
click to toggle source
# File lib/praxis/routing_config.rb, line 42 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 39 def head(path, opts={}) add_route 'HEAD', path, opts end
options(path, opts={})
click to toggle source
# File lib/praxis/routing_config.rb, line 37 def options(path, opts={}) add_route 'OPTIONS', path, opts end
patch(path, opts={})
click to toggle source
# File lib/praxis/routing_config.rb, line 45 def patch(path, opts={}) add_route 'PATCH', path, opts end
post(path, opts={})
click to toggle source
# File lib/praxis/routing_config.rb, line 40 def post(path, opts={}) add_route 'POST', path, opts end
prefix(prefix=nil)
click to toggle source
# File lib/praxis/routing_config.rb, line 24 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..-1]) else @prefix_segments << prefix end end
put(path, opts={})
click to toggle source
# File lib/praxis/routing_config.rb, line 41 def put(path, opts={}) add_route 'PUT', path, opts end
trace(path, opts={})
click to toggle source
# File lib/praxis/routing_config.rb, line 43 def trace(path, opts={}) add_route 'TRACE', path, opts end