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.



62
63
64
# File 'lib/utopia/controller/rewrite.rb', line 62

def initialize
	@rules = []
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



66
67
68
# File 'lib/utopia/controller/rewrite.rb', line 66

def rules
  @rules
end

Instance Method Details

#apply(context, request, path) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/utopia/controller/rewrite.rb', line 72

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

#call(context, request, path) ⇒ Object



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

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

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



68
69
70
# File 'lib/utopia/controller/rewrite.rb', line 68

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