lib/divining_rod/profile.rb in divining_rod-0.4.0 vs lib/divining_rod/profile.rb in divining_rod-0.5.0
- old
+ new
@@ -1,36 +1,37 @@
module DiviningRod
class Profile
- attr_reader :match
-
def initialize(request)
@request = request.clone #Lets not mess with the real one
- @match = DiviningRod::Mappings.evaluate(request)
end
+
+ def match
+ @match ||= DiviningRod::Mappings.evaluate(@request)
+ end
def format
- if @match && @match.format
- @match.format
+ if match && match.format
+ match.format
else
@request.format
end
end
def recognized?
- @match != DiviningRod::Mappings.root_definition
+ match != DiviningRod::Mappings.root_definition
end
def method_missing(meth)
if meth.to_s.match(/(.+)\?$/)
tag = $1
- if @match
- @match.tags.include?(tag.to_s) || @match.tags.include?(tag.to_sym) || @match.tags == tag
+ if match
+ match.tags.include?(tag.to_s) || match.tags.include?(tag.to_sym) || match.tags == tag
else
false
end
- elsif @match.opts.include?(meth.to_sym)
- @match.opts[meth]
+ elsif match.opts.include?(meth.to_sym)
+ match.opts[meth]
else
super
end
end