Skip to content

Commit

Permalink
memoize moderately expensive method
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwhite committed Sep 19, 2009
1 parent 1ce84cd commit 0dccc2d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/ardes/resources_controller/request_path_introspection.rb
@@ -1,7 +1,8 @@
module Ardes
module ResourcesController
module RequestPathIntrospection

extend ActiveSupport::Memoizable

protected
def request_path
@request_path ||= params[:resource_path] || request.path
Expand Down Expand Up @@ -40,6 +41,7 @@ def segments_for_path_and_keys(path, keys)
end
segments
end
memoize :segments_for_path_and_keys

def segment_for_key(key)
if respond_to?(:specifications) && spec = specifications.find{|s| s.respond_to?(:key) && s.key == key.to_s}
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/request_path_introspection_spec.rb
Expand Up @@ -78,7 +78,7 @@ class User < ActiveRecord::Base; end
end
end

describe "when enclosing reosurce has mapping for :user => 'muchachos'" do
describe "when enclosing resource has mapping for :user => 'muchachos'" do
before do
@klass.map_enclosing_resource :user, :segment => "muchachos", :class => RequestPathIntrospectionSpec::User
end
Expand Down

0 comments on commit 0dccc2d

Please sign in to comment.