Class: Tina4::WebSocketRoute
- Inherits:
-
Object
- Object
- Tina4::WebSocketRoute
- Defined in:
- lib/tina4/router.rb
Overview
A registered WebSocket route with path pattern matching (reuses Route’s compile logic)
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#param_names ⇒ Object
readonly
Returns the value of attribute param_names.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#path_regex ⇒ Object
readonly
Returns the value of attribute path_regex.
Instance Method Summary collapse
-
#initialize(path, handler) ⇒ WebSocketRoute
constructor
A new instance of WebSocketRoute.
-
#match?(request_path) ⇒ Boolean
Returns params hash if matched, false otherwise.
Constructor Details
#initialize(path, handler) ⇒ WebSocketRoute
Returns a new instance of WebSocketRoute.
155 156 157 158 159 160 161 |
# File 'lib/tina4/router.rb', line 155 def initialize(path, handler) @path = normalize_path(path).freeze @handler = handler @param_names = [] @path_regex = compile_pattern(@path) @param_names.freeze end |
Instance Attribute Details
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
153 154 155 |
# File 'lib/tina4/router.rb', line 153 def handler @handler end |
#param_names ⇒ Object (readonly)
Returns the value of attribute param_names.
153 154 155 |
# File 'lib/tina4/router.rb', line 153 def param_names @param_names end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
153 154 155 |
# File 'lib/tina4/router.rb', line 153 def path @path end |
#path_regex ⇒ Object (readonly)
Returns the value of attribute path_regex.
153 154 155 |
# File 'lib/tina4/router.rb', line 153 def path_regex @path_regex end |
Instance Method Details
#match?(request_path) ⇒ Boolean
Returns params hash if matched, false otherwise
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/tina4/router.rb', line 164 def match?(request_path) match = @path_regex.match(request_path) return false unless match if @param_names.empty? {} else params = {} @param_names.each_with_index do |param_def, i| raw_value = match[i + 1] params[param_def[:name]] = raw_value end params end end |