class CottonTail::Route
Route
pattern matcher
Public Class Methods
new(pattern)
click to toggle source
Calls superclass method
# File lib/cotton_tail/route.rb, line 6 def initialize(pattern) @pattern = pattern super build_regex end
Public Instance Methods
binding()
click to toggle source
# File lib/cotton_tail/route.rb, line 17 def binding segments.map(&:binding).join('.') end
extract_params(routing_key)
click to toggle source
# File lib/cotton_tail/route.rb, line 11 def extract_params(routing_key) return {} unless match? routing_key match(routing_key).named_captures end
Private Instance Methods
build_regex()
click to toggle source
# File lib/cotton_tail/route.rb, line 44 def build_regex Regexp.new "^#{collapse}$" end
collapse()
click to toggle source
# File lib/cotton_tail/route.rb, line 27 def collapse segments.zip(separators).join end
explode()
click to toggle source
# File lib/cotton_tail/route.rb, line 23 def explode @pattern.split('.').map(&RouteSegment.method(:new)) end
segments()
click to toggle source
# File lib/cotton_tail/route.rb, line 31 def segments @segments ||= explode end
separators()
click to toggle source
# File lib/cotton_tail/route.rb, line 35 def separators separators = segments.each_with_index.map do |segment, idx| [Regexp.escape('.')].tap do |sep| sep << '?' if segment.hash? && idx.zero? end end separators.map(&:join)[0..-2] end