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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRewriter

Returns a new instance of Rewriter.



74
75
76
# File 'lib/utopia/controller/rewrite.rb', line 74

def initialize
	@rules = []
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



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

def rules
  @rules
end

Instance Method Details

#apply(context, request, path) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/utopia/controller/rewrite.rb', line 84

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

#call(context, request, path) ⇒ Object



92
93
94
# File 'lib/utopia/controller/rewrite.rb', line 92

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

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



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

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