Module: Landline::DSL::PathMethods

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

Overview

Common path methods

Instance Method Summary collapse

Instance Method Details

#bounceObject

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.

Parameters:

  • block (#call)

Yield Parameters:



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.

Parameters:

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

    Specify a status code to handle

  • block (#call)

    Block to run on given code



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

Parameters:

  • index (Array, String)


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

Parameters:

  • block (#call)

    block that yields request



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.

Parameters:

  • filename (String)


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.

Parameters:

  • block (#call)

Yield Parameters:



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.

Parameters:

  • block (#call)

Yield Parameters:



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

Parameters:

  • path (String)


50
51
52
# File 'lib/landline/dsl/methods_path.rb', line 50

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

#root(path) ⇒ Object

Set root path (appends matched part of the path).

Parameters:

  • path (String)


44
45
46
# File 'lib/landline/dsl/methods_path.rb', line 44

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