Module: Hyde::DSL::PathMethods

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

Overview

Common path methods

Instance Method Summary collapse

Instance Method Details

#filter(&block) {|request| ... } ⇒ Object

Add a filter to the path. Blocks path access if a filter returns false.

Parameters:

  • block (#call)

Yield Parameters:



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

def filter(&block)
  @origin.filter(&block)
  block
end

#index(index) ⇒ Object

Set path index

Parameters:

  • index (Array, String)


10
11
12
13
14
15
16
17
18
19
# File 'lib/hyde/dsl/methods_path.rb', line 10

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

#plugin(filename) ⇒ Object

Include an application as a child of path.

Parameters:

  • filename (String)


62
63
64
65
66
67
68
69
70
71
72
# File 'lib/hyde/dsl/methods_path.rb', line 62

def plugin(filename)
  self.define_singleton_method(:run) do |object|
    unless object.is_a? Hyde::Node
      raise ArgumentError, "not a node instance or subclass instance"
    end

    object
  end
  @origin.children.append(self.instance_eval(File.read(filename)))
  self.singleton_class.undef_method :run
end

#postprocess(&block) {|request, response| ... } ⇒ Object

Add a postprocessor to the path.

Parameters:

  • block (#call)

Yield Parameters:



46
47
48
49
# File 'lib/hyde/dsl/methods_path.rb', line 46

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:



37
38
39
40
# File 'lib/hyde/dsl/methods_path.rb', line 37

def preprocess(&block)
  @origin.preprocess(&block)
  block
end

#remap(path) ⇒ Object

Set root path (without appending matched part).

Parameters:

  • path (String)


29
30
31
# File 'lib/hyde/dsl/methods_path.rb', line 29

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

#root(path) ⇒ Object

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

Parameters:

  • path (String)


23
24
25
# File 'lib/hyde/dsl/methods_path.rb', line 23

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