Class: Sapp::Path::Base
- Inherits:
-
Object
- Object
- Sapp::Path::Base
- Defined in:
- lib/sapp/path/base.rb
Overview
An Object that builds a path structure for matching. Is used during the addition of routes.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
- #concat_namespace_and_path(path, namespaces) ⇒ Object
- #counter ⇒ Object
- #create_path ⇒ Object
- #extract_keys(key) ⇒ Object
- #extract_keys_and_paths ⇒ Object
- #extract_paths(path) ⇒ Object
-
#initialize(path, options: {}) ⇒ Base
constructor
A new instance of Base.
- #namespace_to_path(namespaces) ⇒ Object
- #namespaces ⇒ Object
- #namespaces?(namespaces) ⇒ Boolean
- #nested?(namespaces) ⇒ Boolean
- #nested_deeply?(namespaces) ⇒ Boolean
- #options? ⇒ Boolean
- #parse ⇒ Object
- #set_original(options, path) ⇒ Object
- #setup_extraction ⇒ Object
Constructor Details
#initialize(path, options: {}) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 14 15 |
# File 'lib/sapp/path/base.rb', line 8 def initialize path, options: {} @original = set_original , path @options = @keys = Hash.new @paths = Hash.new @stream = Array.new @counter = 0 end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
6 7 8 |
# File 'lib/sapp/path/base.rb', line 6 def controller @controller end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
6 7 8 |
# File 'lib/sapp/path/base.rb', line 6 def keys @keys end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/sapp/path/base.rb', line 6 def @options end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
6 7 8 |
# File 'lib/sapp/path/base.rb', line 6 def original @original end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
6 7 8 |
# File 'lib/sapp/path/base.rb', line 6 def paths @paths end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
6 7 8 |
# File 'lib/sapp/path/base.rb', line 6 def stream @stream end |
Instance Method Details
#concat_namespace_and_path(path, namespaces) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# 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 ⇒ Object
114 115 116 |
# File 'lib/sapp/path/base.rb', line 114 def counter @counter end |
#create_path ⇒ Object
104 105 106 107 108 109 110 111 112 |
# 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) ⇒ Object
90 91 92 93 94 95 |
# 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 ⇒ Object
82 83 84 85 86 87 88 |
# 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) ⇒ Object
97 98 99 100 101 102 |
# 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) ⇒ Object
52 53 54 |
# File 'lib/sapp/path/base.rb', line 52 def namespace_to_path namespaces '/' + namespaces.join('/') end |
#namespaces ⇒ Object
68 69 70 |
# File 'lib/sapp/path/base.rb', line 68 def namespaces [:namespaces] end |
#namespaces?(namespaces) ⇒ Boolean
64 65 66 |
# File 'lib/sapp/path/base.rb', line 64 def namespaces? namespaces namespaces && namespaces.any? end |
#nested?(namespaces) ⇒ Boolean
60 61 62 |
# File 'lib/sapp/path/base.rb', line 60 def nested? namespaces namespaces[1] end |
#nested_deeply?(namespaces) ⇒ Boolean
37 38 39 |
# File 'lib/sapp/path/base.rb', line 37 def nested_deeply? namespaces namespaces? namespaces && namespaces.count > 2 end |
#options? ⇒ Boolean
56 57 58 |
# File 'lib/sapp/path/base.rb', line 56 def .any? end |
#parse ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/sapp/path/base.rb', line 17 def parse extract_keys_and_paths set_controller path = create_path ? path.merge() : path end |
#set_original(options, path) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sapp/path/base.rb', line 25 def set_original , path namespaces = [:namespaces] begin if nested_deeply? namespaces raise ArgumentError, "Routes nested too deeply" else concat_namespace_and_path path, namespaces end end end |
#setup_extraction ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/sapp/path/base.rb', line 72 def setup_extraction if original == '/' [original] else path = original.split('/') path.delete("") path end end |