Module: Landline::DSL::PathMethods
- Included in:
- App, PathContext
- Defined in:
- lib/landline/dsl/methods_path.rb
Overview
Common path methods
Instance Method Summary collapse
-
#bounce ⇒ Object
(in Landline::Path context) Bounce request if no handler found instead of issuing 404.
-
#filter(&block) {|request| ... } ⇒ Object
(in Landline::Path context) Add a filter to the path.
-
#handle(code = nil, &block) ⇒ Object
(in Landline::Path context) Create a status code handler on path.
-
#index(index) ⇒ Object
(in Landline::Path context) Set path index.
-
#nobounce ⇒ Object
(in Landline::Path context) Unset bounce.
-
#pipeline(&block) ⇒ Object
(in Landline::Path context) Insert a pass-through pipeline into request processing (i.e. for error handling purposes).
-
#plugin(filename) ⇒ Object
deprecated
Deprecated.
this method is being deprecated due to strong dependency on the framework
-
#postprocess(&block) {|request, response| ... } ⇒ Object
(also: #after)
(in Landline::Path context) Add a postprocessor to the path.
-
#preprocess(&block) {|request| ... } ⇒ Object
(also: #before)
(in Landline::Path context) Add a preprocessor to the path.
-
#remap(path) ⇒ Object
(in Landline::Path context) Set root path (without appending matched part).
-
#root(path) ⇒ Object
(in Landline::Path context) Set root path (appends matched part of the path).
Instance Method Details
#bounce ⇒ Object
(in Landline::Path context) Bounce request if no handler found instead of issuing 404
10 11 12 |
# File 'lib/landline/dsl/methods_path.rb', line 10 def bounce @origin.bounce = true end |
#filter(&block) {|request| ... } ⇒ Object
(in Landline::Path context) Add a filter to the path. Blocks path access if a filter returns false.
94 95 96 97 |
# File 'lib/landline/dsl/methods_path.rb', line 94 def filter(&block) @origin.filter(&block) block end |
#handle(code = nil, &block) ⇒ Object
(in Landline::Path context) Create a status code handler on path. Recursively applies to all paths unless overridden.
25 26 27 |
# File 'lib/landline/dsl/methods_path.rb', line 25 def handle(code = nil, &block) @origin.properties["handle.#{code || 'default'}"] = block end |
#index(index) ⇒ Object
(in Landline::Path context) Set path index
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/landline/dsl/methods_path.rb', line 41 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 |
#nobounce ⇒ Object
(in Landline::Path context) Unset bounce
16 17 18 |
# File 'lib/landline/dsl/methods_path.rb', line 16 def nobounce @origin.bounce = false end |
#pipeline(&block) ⇒ Object
(in Landline::Path context) Insert a pass-through pipeline into request processing (i.e. for error handling purposes). Passed block should yield request (and return yielded data back).
34 35 36 |
# File 'lib/landline/dsl/methods_path.rb', line 34 def pipeline(&block) @origin.pipeline = block end |
#plugin(filename) ⇒ Object
this method is being deprecated due to strong dependency on the framework
(in Landline::Path context) Include an application as a child of path.
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/landline/dsl/methods_path.rb', line 103 def plugin(filename) 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( instance_eval(File.read(filename), filename) ) singleton_class.undef_method :run end |
#postprocess(&block) {|request, response| ... } ⇒ Object Also known as: after
(in Landline::Path context) Add a postprocessor to the path.
81 82 83 84 |
# File 'lib/landline/dsl/methods_path.rb', line 81 def postprocess(&block) @origin.postprocess(&block) block end |
#preprocess(&block) {|request| ... } ⇒ Object Also known as: before
(in Landline::Path context) Add a preprocessor to the path. Does not modify path execution.
71 72 73 74 |
# File 'lib/landline/dsl/methods_path.rb', line 71 def preprocess(&block) @origin.preprocess(&block) block end |
#remap(path) ⇒ Object
(in Landline::Path context) Set root path (without appending matched part).
62 63 64 |
# File 'lib/landline/dsl/methods_path.rb', line 62 def remap(path) @origin.remap = File.(path) end |