Module: Landline::DSL::PathMethods

Included in:
App, PathContext
Defined in:
lib/landline/dsl/methods_path.rb

Overview

Common path methods

Instance Method Summary collapse

Instance Method Details

#bounceObject

(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.

Parameters:

  • block (#call)

Yield Parameters:



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.

Parameters:

  • code (Integer, nil) (defaults to: nil)

    Specify a status code to handle

  • block (#call)

    Block to run on given code



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

Parameters:

  • index (Array, String)


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

#nobounceObject

(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).

Parameters:

  • block (#call)

    block that yields request



34
35
36
# File 'lib/landline/dsl/methods_path.rb', line 34

def pipeline(&block)
  @origin.pipeline = block
end

#plugin(filename) ⇒ Object

Deprecated.

this method is being deprecated due to strong dependency on the framework

(in Landline::Path context) Include an application as a child of path.

Parameters:

  • filename (String)


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.

Parameters:

  • block (#call)

Yield Parameters:



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.

Parameters:

  • block (#call)

Yield Parameters:



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).

Parameters:

  • path (String)


62
63
64
# File 'lib/landline/dsl/methods_path.rb', line 62

def remap(path)
  @origin.remap = File.expand_path(path)
end

#root(path) ⇒ Object

(in Landline::Path context) Set root path (appends matched part of the path).

Parameters:

  • path (String)


55
56
57
# File 'lib/landline/dsl/methods_path.rb', line 55

def root(path)
  @origin.root = File.expand_path(path)
end