Class: Vayacondios::Rack::Path

Inherits:
Object
  • Object
show all
Includes:
Goliath::Rack::AsyncMiddleware
Defined in:
lib/vayacondios/server/rack/path.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



6
7
8
9
# File 'lib/vayacondios/server/rack/path.rb', line 6

def call(env)
  path_params = parse_path(env[Goliath::Request::REQUEST_PATH])
  super env.merge(vayacondios_path: path_params)
end

#parse_path(path) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/vayacondios/server/rack/path.rb', line 11

def parse_path(path)
  path_regex = /^\/v1\/(?<organization>[a-z]\w+)\/(?<type>config|event|itemset)(\/(?<topic>\w+)(\/(?<id>(\w+\/?)+))?)?(\/|\.(?<format>json))?$/i
  if (match = path_regex.match(path))
    {}.tap do |segments|
      match.names.each do |segment|
        segments[segment.to_sym] = match[segment]
      end
    end
  end
end