Class: Utopia::Controller::Rewrite::ExtractPrefixRule

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

Instance Attribute Summary

Attributes inherited from Rule

#arguments, #block

Instance Method Summary collapse

Methods inherited from Rule

#apply_match_to_context

Constructor Details

#initialize(arguments, block) ⇒ ExtractPrefixRule

Returns a new instance of ExtractPrefixRule.



57
58
59
60
61
# File 'lib/utopia/controller/rewrite.rb', line 57

def initialize(arguments, block)
	@matcher = Path::Matcher.new(arguments)
	
	super
end

Instance Method Details

#apply(context, request, path) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/utopia/controller/rewrite.rb', line 69

def apply(context, request, path)
	if match_data = @matcher.match(path)
		apply_match_to_context(match_data, context)
		
		if @block
			context.instance_exec(request, path, match_data, &@block)
		end
		
		return match_data.post_match
	else
		return path
	end
end

#freezeObject



63
64
65
66
67
# File 'lib/utopia/controller/rewrite.rb', line 63

def freeze
	@matcher.freeze
	
	super
end