class Sapp::Path::Request
Attributes
handler[R]
keys[R]
path[R]
routes[R]
verb[R]
Public Class Methods
new(original, verb, routes)
click to toggle source
# File lib/sapp/path/request.rb, line 9 def initialize original, verb, routes @original = original @verb = verb @routes = routes @keys = Hash.new @handler = nil end
Public Instance Methods
check_methods?(p, hash)
click to toggle source
# File lib/sapp/path/request.rb, line 91 def check_methods? p, hash (p[:methods].values - hash.values).empty? end
check_stream?(p, hash)
click to toggle source
# File lib/sapp/path/request.rb, line 87 def check_stream? p, hash p[:stream].count == hash.values.count end
extract_key(k)
click to toggle source
# File lib/sapp/path/request.rb, line 78 def extract_key k key = path[:keys][k] key.tr(':', '').to_sym end
extract_keys()
click to toggle source
Remove the first key:value(controller) return a hash with keys from path
# File lib/sapp/path/request.rb, line 62 def extract_keys hash = Hash.new sort_path.each do |k, v| if path[:keys].include?(k) && k > 0 hash[extract_key(k)] = v end end hash end
find_controller()
click to toggle source
# File lib/sapp/path/request.rb, line 83 def find_controller routes[verb][controller] end
find_path()
click to toggle source
Matches by method names and stream count, returns best match
# File lib/sapp/path/request.rb, line 39 def find_path match_by_methods_and_stream end
key?(k)
click to toggle source
# File lib/sapp/path/request.rb, line 74 def key? k k > 0 end
match_by_methods_and_stream()
click to toggle source
Returns hash of matched paths by stream count and method name
# File lib/sapp/path/request.rb, line 34 def match_by_methods_and_stream match_by_stream_count.select { |p| check_methods? p, sort_path } end
match_by_stream_count()
click to toggle source
Returns hash of matched paths by stream count
# File lib/sapp/path/request.rb, line 29 def match_by_stream_count paths.select { |p| check_stream? p, sort_path } end
parse()
click to toggle source
Sets controller, path keys and handler
# File lib/sapp/path/request.rb, line 18 def parse set_controller if path? @path = find_path.uniq.first @keys = extract_keys @handler = @path[:handler] end end
path?()
click to toggle source
Returns boolean, is handler defined?
# File lib/sapp/path/request.rb, line 101 def path? find_controller && find_path.any? end
paths()
click to toggle source
Return paths from request controller
# File lib/sapp/path/request.rb, line 44 def paths find_controller[:paths] end
set_controller()
click to toggle source
Sets the controller based off the first key:value pair
# File lib/sapp/path/request.rb, line 96 def set_controller @controller = sort_path[0] end
sort_path()
click to toggle source
Parses path by ‘/’ and creates a numbered dictionary EX: { 0 => ‘user’ }
# File lib/sapp/path/request.rb, line 49 def sort_path reset_counter array = Array.new setup_extraction.each do |v| array << [counter, v] count end @sort_path ||= Hash[array] end