Class: Utopia::Controller::Rewrite::Rewriter

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/controller/rewrite.rb

Overview

Rewrite a request path based on a set of defined rules.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRewriter

Returns a new instance of Rewriter



77
78
79
# File 'lib/utopia/controller/rewrite.rb', line 77

def initialize
	@rules = []
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules



81
82
83
# File 'lib/utopia/controller/rewrite.rb', line 81

def rules
  @rules
end

Instance Method Details

#apply(context, request, path) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/utopia/controller/rewrite.rb', line 87

def apply(context, request, path)
	@rules.each do |rule|
		path = rule.apply(context, request, path)
	end
	
	return path
end

#call(context, request, path) ⇒ Object



95
96
97
# File 'lib/utopia/controller/rewrite.rb', line 95

def call(context, request, path)
	path.components = apply(context, request, path).components
end

#extract_prefix(**patterns, &block) ⇒ Object



83
84
85
# File 'lib/utopia/controller/rewrite.rb', line 83

def extract_prefix(**patterns, &block)
	@rules << ExtractPrefixRule.new(patterns, block)
end