Class: Hyde::Path
Overview
Primary building block of request navigation.
Direct Known Subclasses
Constant Summary collapse
- ProcContext =
Hyde::ProcessorContext
- Context =
Hyde::PathContext
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#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.
-
#initialize(path, parent:, &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:, &setup) ⇒ Path
Returns a new instance of Path.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hyde/path.rb', line 38 def initialize(path, parent:, &setup) super(path, parent: parent) # 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) @proccontext = self.class::ProcContext.new(self) end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
98 99 100 |
# File 'lib/hyde/path.rb', line 98 def children @children end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
98 99 100 |
# File 'lib/hyde/path.rb', line 98 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.
94 95 96 |
# File 'lib/hyde/path.rb', line 94 def filter(&block) @filters.append(block) end |
#postprocess(&block) {|request, response| ... } ⇒ Object
Add a postprocessor to the path.
86 87 88 |
# File 'lib/hyde/path.rb', line 86 def postprocess(&block) @postprocessors.append(block) end |
#preprocess(&block) {|request| ... } ⇒ Object
Add a preprocessor to the path. Does not modify path execution.
78 79 80 |
# File 'lib/hyde/path.rb', line 78 def preprocess(&block) @preprocessors.append(block) end |
#process(request) ⇒ Boolean
Method callback on successful request navigation. Finds the next appropriate path to go to.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/hyde/path.rb', line 56 def process(request) return false unless run_filters(request) run_preprocessors(request) enqueue_postprocessors(request) @children.each do |x| if (value = x.go(request)) return value end end value = index(request) return value if value _die(404) rescue StandardError => e _die(500, backtrace: [e.to_s] + e.backtrace) end |