Class: Orbit::Routing::Pattern

Inherits:
Object
  • Object
show all
Defined in:
lib/orbit/routing/pattern.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(segment) ⇒ Pattern

Returns a new instance of Pattern.



4
5
6
7
8
# File 'lib/orbit/routing/pattern.rb', line 4

def initialize(segment)
  @segment = segment
  @ignore = []
  @keys = []
end

Class Method Details

.resolve(segment) ⇒ Object



10
11
12
# File 'lib/orbit/routing/pattern.rb', line 10

def self.resolve(segment)
  new(segment).resolve
end

Instance Method Details

#resolveObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/orbit/routing/pattern.rb', line 14

def resolve
  result = pattern.gsub(/((:\w+)|\*)/) do |match|
    if match == "*"
      keys << 'splat'
      "(.*?)"
    else
      keys << $2[1..-1]
      safe_ignore
    end
  end

  [keys, ignore, result]
end