Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
Refactor dynamic finder away from class_eval with a string
Browse files Browse the repository at this point in the history
simplify getting the class to define dynamic finders on
  • Loading branch information
tooky committed Mar 9, 2010
1 parent baf3733 commit 628e579
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
tmp
.*.sw?
tmp
8 changes: 4 additions & 4 deletions lib/document/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ def index(key_name, options={})

method_name = 'find_by_'+(options[:as] or key_name).to_s
if viable_method_name(method_name)
(class << self; self; end).class_eval %{
def #{method_name}(value)
collection.find(:#{key_name} => value).map{|bson_hash| new(bson_hash)}
self.class.class_eval do
define_method method_name.to_sym do |value|
collection.find(key_name.to_sym => value).map{|bson_hash| new(bson_hash)}
end
}
end
end

collection.create_index(key_name)
Expand Down

0 comments on commit 628e579

Please sign in to comment.