Class: Landline::Node Abstract
- Inherits:
-
Object
- Object
- Landline::Node
- Defined in:
- lib/landline/node.rb
Overview
This class is abstract.
Abstract class that reacts to request navigation. Does nothing by default, behaviour should be overriden through #reject and #process
Instance Attribute Summary collapse
-
#remap ⇒ Object
Returns the value of attribute remap.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
-
#go(request) ⇒ Boolean
Try to navigate the path.
-
#initialize(path, parent:, filepath: true) ⇒ Node
constructor
A new instance of Node.
-
#process(_request) ⇒ Object
Method callback on successful request navigation.
-
#reject(_request) ⇒ Object
Method callback on failed request navigation.
Constructor Details
#initialize(path, parent:, filepath: true) ⇒ Node
Returns a new instance of Node.
13 14 15 16 17 18 19 |
# File 'lib/landline/node.rb', line 13 def initialize(path, parent:, filepath: true) @pattern = Pattern.new(path).freeze @properties = Landline::Util::Lookup.new(parent&.properties) @root = nil @remap = false @modify_filepath = filepath end |
Instance Attribute Details
#remap ⇒ Object
Returns the value of attribute remap.
71 72 73 |
# File 'lib/landline/node.rb', line 71 def remap @remap end |
#root ⇒ Object
Returns the value of attribute root.
71 72 73 |
# File 'lib/landline/node.rb', line 71 def root @root end |
Instance Method Details
#go(request) ⇒ Boolean
Try to navigate the path. Run method callback in response.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/landline/node.rb', line 40 def go(request) # rejected at pattern return reject(request) unless @pattern.match?(request.path) request.push_state path, splat, param = @pattern.match(request.path) do_filepath(request, request.path.delete_suffix(path)) request.path = path request.splat.append(*splat) request.param.merge!(param) value = process(request) # rejected at callback - restore state request.pop_state unless value # finally, return process value value end |
#process(_request) ⇒ Object
Method callback on successful request navigation
67 68 69 |
# File 'lib/landline/node.rb', line 67 def process(_request) true end |
#reject(_request) ⇒ Object
Method callback on failed request navigation
60 61 62 |
# File 'lib/landline/node.rb', line 60 def reject(_request) false end |