class Pakyow::Routing::Route
A {Controller} endpoint.
Attributes
block[R]
method[R]
name[R]
path[R]
pipeline[RW]
@api private
Public Class Methods
new(path_or_matcher, name:, method:, &block)
click to toggle source
# File lib/pakyow/routing/route.rb, line 18 def initialize(path_or_matcher, name:, method:, &block) @name, @method, @block = name, method, block if path_or_matcher.is_a?(String) @path = path_or_matcher.to_s @matcher = create_matcher_from_path(@path) else @path = "" @matcher = path_or_matcher end end
Public Instance Methods
build_path(path_to_self, **params)
click to toggle source
# File lib/pakyow/routing/route.rb, line 38 def build_path(path_to_self, **params) working_path = String.normalize_path(File.join(path_to_self.to_s, @path)) params.each do |key, value| working_path.sub!(":#{key}", value.to_s) end working_path.sub!("/#", "#") working_path end
call(context)
click to toggle source
# File lib/pakyow/routing/route.rb, line 34 def call(context) context.instance_exec(&@block) if @block end
match(path_to_match)
click to toggle source
# File lib/pakyow/routing/route.rb, line 30 def match(path_to_match) @matcher.match(path_to_match) end
Private Instance Methods
create_matcher_from_path(path)
click to toggle source
# File lib/pakyow/routing/route.rb, line 51 def create_matcher_from_path(path) converted_path = String.normalize_path(path.split("/").map { |segment| if segment.include?(":") "(?<#{segment[(segment.index(":") + 1)..-1]}>(\\w|[-~:@!$\\'\\(\\)\\*\\+,;])+)" else segment end }.join("/")) Regexp.new("^#{converted_path}$") end