Method: Jets::Controller::Middleware::Local::RouteMatcher#capture_detection

Defined in:
lib/jets/controller/middleware/local/route_matcher.rb

#capture_detection(route_path, actual_path) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/jets/controller/middleware/local/route_matcher.rb', line 78

def capture_detection(route_path, actual_path)
  # changes path to a string used for a regexp
  # posts/:id/edit => posts\/(.*)\/edit

  regexp_string = route_path.split('/').map do |s|
                    s.include?(':') ? Jets::Route::CAPTURE_REGEX : s
                  end.join('\/')
  # make sure beginning and end of the string matches
  regexp_string = "^#{regexp_string}$"

  regexp = Regexp.new(regexp_string)
  !!regexp.match(actual_path) # could be true or false
end