Module: Landline::DSL::PathMethods
- Included in:
- PathContext
- Defined in:
- lib/landline/dsl/methods_path.rb
Overview
Common path methods
Instance Method Summary collapse
-
#bounce ⇒ Object
Bounce request if no handler found instead of issuing 404.
-
#filter(&block) {|request| ... } ⇒ Object
Add a filter to the path.
-
#handle(code = nil, &block) ⇒ Object
Create a status code handler on path.
-
#index(index) ⇒ Object
Set path index.
-
#pipeline(&block) ⇒ Object
Insert a pass-through pipeline into request processing (i.e. for error handling purposes).
-
#plugin(filename) ⇒ Object
Include an application as a child of path.
-
#postprocess(&block) {|request, response| ... } ⇒ Object
Add a postprocessor to the path.
-
#preprocess(&block) {|request| ... } ⇒ Object
Add a preprocessor to the path.
-
#remap(path) ⇒ Object
Set root path (without appending matched part).
-
#root(path) ⇒ Object
Set root path (appends matched part of the path).
Instance Method Details
#bounce ⇒ Object
Bounce request if no handler found instead of issuing 404
9 10 11 |
# File 'lib/landline/dsl/methods_path.rb', line 9 def bounce @origin.bounce = true end |
#filter(&block) {|request| ... } ⇒ Object
Add a filter to the path. Blocks path access if a filter returns false.
76 77 78 79 |
# File 'lib/landline/dsl/methods_path.rb', line 76 def filter(&block) @origin.filter(&block) block end |
#handle(code = nil, &block) ⇒ Object
Create a status code handler on path. Recursively applies to all paths unless overridden.
17 18 19 |
# File 'lib/landline/dsl/methods_path.rb', line 17 def handle(code = nil, &block) @origin.properties["handle.#{code || 'default'}"] = block end |
#index(index) ⇒ Object
Set path index
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/landline/dsl/methods_path.rb', line 31 def index(index) case index when Array @origin.properties['index'] = index when String @origin.properties['index'] = [index] else raise ArgumentError, "index should be an Array or a String" end end |
#pipeline(&block) ⇒ Object
Insert a pass-through pipeline into request processing (i.e. for error handling purposes). Passed block should yield request (and return yielded data back).
25 26 27 |
# File 'lib/landline/dsl/methods_path.rb', line 25 def pipeline(&block) @origin.pipeline = block end |
#plugin(filename) ⇒ Object
Include an application as a child of path.
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/landline/dsl/methods_path.rb', line 83 def plugin(filename) self.define_singleton_method(:run) do |object| unless object.is_a? Landline::Node raise ArgumentError, "not a node instance or subclass instance" end object end @origin.children.append( self.instance_eval(File.read(filename), filename) ) self.singleton_class.undef_method :run end |
#postprocess(&block) {|request, response| ... } ⇒ Object
Add a postprocessor to the path.
67 68 69 70 |
# File 'lib/landline/dsl/methods_path.rb', line 67 def postprocess(&block) @origin.postprocess(&block) block end |
#preprocess(&block) {|request| ... } ⇒ Object
Add a preprocessor to the path. Does not modify path execution.
58 59 60 61 |
# File 'lib/landline/dsl/methods_path.rb', line 58 def preprocess(&block) @origin.preprocess(&block) block end |
#remap(path) ⇒ Object
Set root path (without appending matched part).
50 51 52 |
# File 'lib/landline/dsl/methods_path.rb', line 50 def remap(path) @origin.remap = path end |