Class: Hyde::Path
Overview
Primary building block of request navigation.
Direct Known Subclasses
Constant Summary collapse
- Binding =
Hyde::PathBinding
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.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/hyde/path.rb', line 27 def initialize(path, parent:, &setup) super(path, parent: parent) # Child nodes array @children = [] # Arrays of preprocessors, postprocessors and filters @preprocessors = [] @postprocessors = [] @filters = [] binding = Binding.new(self) binding.instance_exec(&setup) end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
86 87 88 |
# File 'lib/hyde/path.rb', line 86 def children @children end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
86 87 88 |
# File 'lib/hyde/path.rb', line 86 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.
82 83 84 |
# File 'lib/hyde/path.rb', line 82 def filter(&block) @filters.append(block) end |
#postprocess(&block) {|request, response| ... } ⇒ Object
Add a postprocessor to the path.
74 75 76 |
# File 'lib/hyde/path.rb', line 74 def postprocess(&block) @postprocessors.append(block) end |
#preprocess(&block) {|request| ... } ⇒ Object
Add a preprocessor to the path. Does not modify path execution.
66 67 68 |
# File 'lib/hyde/path.rb', line 66 def preprocess(&block) @preprocessors.append(block) end |
#process(request) ⇒ Boolean
Method callback on successful request navigation. Finds the next appropriate path to go to.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/hyde/path.rb', line 44 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 |