class Sapp::Path::Base
An Object that builds a path structure for matching. Is used during the addition of routes.
Attributes
controller[R]
keys[R]
options[R]
original[R]
paths[R]
stream[R]
Public Class Methods
new(path, options: {})
click to toggle source
# File lib/sapp/path/base.rb, line 8 def initialize path, options: {} @original = set_original options, path @options = options @keys = Hash.new @paths = Hash.new @stream = Array.new @counter = 0 end
Public Instance Methods
concat_namespace_and_path(path, namespaces)
click to toggle source
# File lib/sapp/path/base.rb, line 41 def concat_namespace_and_path path, namespaces if namespaces? namespaces x = namespace_to_path namespaces[0] y = nested?(namespaces) ? namespace_to_path(namespaces[1]) : "" x + path + y else path end end
counter()
click to toggle source
# File lib/sapp/path/base.rb, line 114 def counter @counter end
create_path()
click to toggle source
# File lib/sapp/path/base.rb, line 104 def create_path { controller: @controller, stream: stream, keys: keys, methods: paths, original: original, } end
extract_keys(key)
click to toggle source
# File lib/sapp/path/base.rb, line 90 def extract_keys key if key.match(/\A:/) stream << 0 keys[counter] = key end end
extract_keys_and_paths()
click to toggle source
# File lib/sapp/path/base.rb, line 82 def extract_keys_and_paths setup_extraction.each do |values| extract_keys values extract_paths values count end end
extract_paths(path)
click to toggle source
# File lib/sapp/path/base.rb, line 97 def extract_paths path unless path.match(/\A:/) stream << 1 paths[counter] = path end end
namespace_to_path(namespaces)
click to toggle source
# File lib/sapp/path/base.rb, line 52 def namespace_to_path namespaces '/' + namespaces.join('/') end
namespaces()
click to toggle source
# File lib/sapp/path/base.rb, line 68 def namespaces options[:namespaces] end
namespaces?(namespaces)
click to toggle source
# File lib/sapp/path/base.rb, line 64 def namespaces? namespaces namespaces && namespaces.any? end
nested?(namespaces)
click to toggle source
# File lib/sapp/path/base.rb, line 60 def nested? namespaces namespaces[1] end
nested_deeply?(namespaces)
click to toggle source
# File lib/sapp/path/base.rb, line 37 def nested_deeply? namespaces namespaces? namespaces && namespaces.count > 2 end
options?()
click to toggle source
# File lib/sapp/path/base.rb, line 56 def options? options.any? end
parse()
click to toggle source
# File lib/sapp/path/base.rb, line 17 def parse extract_keys_and_paths set_controller path = create_path options? ? path.merge(options) : path end
set_original(options, path)
click to toggle source
# File lib/sapp/path/base.rb, line 25 def set_original options, path namespaces = options[:namespaces] begin if nested_deeply? namespaces raise ArgumentError, "Routes nested too deeply" else concat_namespace_and_path path, namespaces end end end
setup_extraction()
click to toggle source
# File lib/sapp/path/base.rb, line 72 def setup_extraction if original == '/' [original] else path = original.split('/') path.delete("") path end end
Private Instance Methods
count()
click to toggle source
# File lib/sapp/path/base.rb, line 128 def count @counter += 1 end
reset_counter()
click to toggle source
# File lib/sapp/path/base.rb, line 132 def reset_counter @counter = 0 end
set_controller()
click to toggle source
# File lib/sapp/path/base.rb, line 120 def set_controller if @controller = paths[0] paths.delete 0 else raise ArgumentError, "A Path can't begin with a symbol" end end