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.



79
80
81
# File 'lib/utopia/controller/rewrite.rb', line 79

def initialize
	@rules = []
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



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

def rules
  @rules
end

Instance Method Details

#apply(context, request, path) ⇒ Object



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

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

#call(context, request, path) ⇒ Object



97
98
99
# File 'lib/utopia/controller/rewrite.rb', line 97

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

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



85
86
87
# File 'lib/utopia/controller/rewrite.rb', line 85

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