Permalink
Browse files

Changed the find method to accept options for conditions

  • Loading branch information...
1 parent eb14d9d commit 13817db925101749a0036a2447832acb8d785593 @genki genki committed May 9, 2009
View
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = %q{dm-is-taggable}
- s.version = "0.1.5"
+ s.version = "0.1.6"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Aaron Qian, Maxime Guilbot"]
@@ -55,12 +55,16 @@ def find_taggables(options)
return rv
end
- query = { taggable_class.tags.tag.name => tag_list.to_a,
+ query = {
+ taggable_class.tags.tag.name => tag_list.to_a,
Tagging.properties[:taggable_type] => taggable_class.to_s,
- :unique => true
- }
- query.merge!(Tagging.properties[:tagger_type] => tagger_class) if tagger_class
- query.merge!(Tagging.properties[:tagger_id] => tagger_obj.id) if tagger_obj
+ :unique => true
+ }
+ query.merge!(Tagging.properties[:tagger_type] => tagger_class) if tagger_class
+ query.merge!(Tagging.properties[:tagger_id] => tagger_obj.id) if tagger_obj
+ (options.keys - [:match]).each do |key|
+ query[key] = options[key]
+ end
unless options[:match] == :any
conditions = "SELECT COUNT(DISTINCT(tag_id)) FROM taggings INNER JOIN tags ON taggings.tag_id = tags.id WHERE "
@@ -186,4 +190,4 @@ def tagged_count(conditions={})
end # InstanceMethods
end
end
-end
+end
@@ -51,8 +51,8 @@ def taggable?;true;end
def taggable_class;self;end
def find(options)
- tagger, taggable, tags, options = extract_options(options)
- options.merge!(:on => self, :by =>tagger, :with => tags)
+ tagger, taggable, tags, options = extract_options(options)
+ options.merge!(:on => self, :by =>tagger, :with => tags)
Tag.find_taggables(options)
end
@@ -1,7 +1,7 @@
module DataMapper
module Is
module Taggable
- VERSION = "0.1.5"
+ VERSION = "0.1.6"
DEPENDENCY_VERSION = ">= 0.9.6"
end
end
@@ -297,5 +297,10 @@
item[1].should be_a(Integer)
end
end
+
+ it "should be able to specify conditions over find method" do
+ result = Picture.find(:with => 'tag1', :id.not => [1])
+ result.map(&:id).should_not be_include(1)
+ end
end
end

0 comments on commit 13817db

Please sign in to comment.