Module: Rack::Reqorder::GrapeRecognizer

Included in:
Rack::Reqorder
Defined in:
lib/rack/reqorder/route_recognizers.rb

Instance Method Summary collapse

Instance Method Details

#grape_recognize_path(path_uri:, rack_app:, options: {}) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/rack/reqorder/route_recognizers.rb', line 100

def grape_recognize_path(path_uri:, rack_app:, options: {})
  path_uri = '/' if path_uri.blank?

  rack_app.routes.each do |route|
    route_options = route.instance_variable_get(:@options)
    if route_options[:method] == options[:method] && route_options[:compiled] =~ path_uri
     if route_options[:method] == "OPTIONS"
       return route_options[:path].
         gsub('(.json)', '')
     else
       return route_options[:path].
         gsub(':version', route_options[:version]).
         gsub('(.json)', '')
     end
    end
  end

  #assets in grape? well you never know..
  if path_uri.end_with?('.js')
    return '/js_asset'
  elsif path_uri.end_with?('.css')
    return '/css_asset'
  elsif path_uri.end_with?('.png', 'jpg')
    return '/css_asset'
  else
    return '/unknown' #path_uri
  end
end

#recognize_path(path_uri, options = {}) ⇒ Object



96
97
98
# File 'lib/rack/reqorder/route_recognizers.rb', line 96

def recognize_path(path_uri, options = {})
  raise 'not implemented yet'
end