Class: Landline::Path
Overview
Primary building block of request navigation.
Direct Known Subclasses
Constant Summary collapse
- Context =
Landline::PathContext
Instance Attribute Summary collapse
-
#bounce ⇒ Object
Returns the value of attribute bounce.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#pipeline ⇒ Object
Returns the value of attribute pipeline.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Attributes inherited from Node
Instance Method Summary collapse
-
#filter(&block) {|request| ... } ⇒ Object
Add a filter to the path.
-
#go(request) ⇒ Boolean
Try to navigate the path.
-
#initialize(path, parent:, **params, &setup) ⇒ Path
constructor
A new instance of Path.
-
#postprocess(&block) {|request, response| ... } ⇒ Object
Add a postprocessor to the path.
-
#preprocess(&block) {|request| ... } ⇒ Object
Add a preprocessor to the path.
-
#process(request) ⇒ Boolean
Method callback on successful request navigation.
Methods inherited from Node
Constructor Details
#initialize(path, parent:, **params, &setup) ⇒ Path
Returns a new instance of Path.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/landline/path.rb', line 27 def initialize(path, parent:, **params, &setup) super(path, parent: parent, **params) # Child nodes array @children = [] # Arrays of preprocessors, postprocessors and filters @preprocessors = [] @postprocessors = [] @filters = [] # Contexts setup context = self.class::Context.new(self) context.instance_exec(&setup) end |
Instance Attribute Details
#bounce ⇒ Object
Returns the value of attribute bounce.
96 97 98 |
# File 'lib/landline/path.rb', line 96 def bounce @bounce end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
94 95 96 |
# File 'lib/landline/path.rb', line 94 def children @children end |
#pipeline ⇒ Object
Returns the value of attribute pipeline.
96 97 98 |
# File 'lib/landline/path.rb', line 96 def pipeline @pipeline end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
94 95 96 |
# File 'lib/landline/path.rb', line 94 def properties @properties end |
Instance Method Details
#filter(&block) {|request| ... } ⇒ Object
Add a filter to the path. Blocks path access if a filter returns false.
90 91 92 |
# File 'lib/landline/path.rb', line 90 def filter(&block) @filters.append(block) end |
#go(request) ⇒ Boolean
Try to navigate the path. Run method callback in response.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/landline/path.rb', line 41 def go(request) # This is done to allow pipeline to interject handlers # I'm more than willing to admit that this is stupid, # but it is well worth the logical flexibility. if ['handle.default', 'handle.505'].any? do |x| @properties.storage.include? x end begin super(request) rescue StandardError => e _die(request, 500, backtrace: [e.to_s] + e.backtrace, error: e) end else super(request) end end |
#postprocess(&block) {|request, response| ... } ⇒ Object
Add a postprocessor to the path.
82 83 84 |
# File 'lib/landline/path.rb', line 82 def postprocess(&block) @postprocessors.append(block) end |
#preprocess(&block) {|request| ... } ⇒ Object
Add a preprocessor to the path. Does not modify path execution.
74 75 76 |
# File 'lib/landline/path.rb', line 74 def preprocess(&block) @preprocessors.append(block) end |
#process(request) ⇒ Boolean
Method callback on successful request navigation. Finds the next appropriate path to go to.
62 63 64 65 66 67 68 |
# File 'lib/landline/path.rb', line 62 def process(request) if @pipeline @pipeline.call(request) { |inner_req| process_wrapped(inner_req) } else process_wrapped(request) end end |