From bf9b93d952340f2e3257b395a47bc79c60bdd83e Mon Sep 17 00:00:00 2001 From: Kristian Mandrup Date: Fri, 24 Jun 2011 19:09:52 +0200 Subject: [PATCH] updated to work with Mongoid 2.0.2 and above --- .rspec | 1 + Gemfile | 8 +++--- README.markdown => README.textile | 41 +++++++++++++++++------------ Rakefile | 43 +++---------------------------- VERSION | 2 +- lib/mongoid/embedded_helper.rb | 6 ++--- 6 files changed, 37 insertions(+), 64 deletions(-) create mode 100644 .rspec rename README.markdown => README.textile (77%) diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..7abe2a1 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--color --format nested \ No newline at end of file diff --git a/Gemfile b/Gemfile index e744a95..39a212d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,10 @@ source :gemcutter -gem 'mongoid', '>=2.0.0.rc.7' -gem "mongoid_adjust", ">= 0.1.1" -gem 'bson_ext', '>=1.0.1' +gem 'mongoid', '>= 2.0.2' +gem "mongoid_adjust", '>= 0.1.1' +gem 'bson_ext', '>= 1.0.1' group :test do - gem 'rspec', '>= 2.0.0.beta.15' + gem 'rspec', '>= 2.4.0' gem 'mocha' end diff --git a/README.markdown b/README.textile similarity index 77% rename from README.markdown rename to README.textile index c3a154b..bc11ef6 100644 --- a/README.markdown +++ b/README.textile @@ -1,24 +1,29 @@ -# Mongoid embedded helper # +h1. Mongoid embedded helper The Mongoid EmbeddedHelper helps overcome the limitation that you can't perform direct queries on an embedded collection without accessing it from the root. It simply introduces a generic function that performs the "local" query by accessing it from the nearest root ;) -## Update +h2. Update June 24, 2011 -In the latest release (0.3.0) the #assimilate method has been removed in order to work with Mongoid 2.0.0.rc1 +In the latest release (0.3.1) the gem has been tested to work with Mongoid 2.0.2 (run the specs!) -## Installation ## +h2. Install -gem install mongoid_embedded_helper +In Gemfile: -## Usage ## +@gem 'mongoid_embedded_helper'@ + +Run bundler + +@$ bundle@ + +h2. Usage Mongoid doesn't allow you to perform direct queries on an embedded collection. You have to access the embedded collection from the root in order to do this. To overcome this limitation, use the EmbeddedHelper module to add a method query_class which will find the closest non-embedded node in the hierarchy and then traverse down the path back to the object, so that you can perform the query on the embedded collection. -
-require 'mongoid_embedded_helper'
+
require 'mongoid_embedded_helper'
 
 class Item
   include Mongoid::Document      
@@ -35,11 +40,13 @@ item.query_class.where(:number.gt => 1).to_a
   
 
-## Adjust! +h2. Adjust! An as added bonus, an extra adjust! method has been added to Document, Criteria and Array. This enables multi-mutation of attributes! +This functionality comes along from the _mongoid_adjust_ gem. + +Here an example using a number -*Here an example using a number*
 it "should times all positions (greater than 1) by 2" do
   result = @person.lists[0].items.where(:pos.gt => 1).adjust!(:pos => lambda {|e| e * 2})
@@ -49,7 +56,8 @@ end
 
 Passing a number is a convenience shortcut for adding a number instead of having to use the Proc approach as shown below.
 
-*Here an example using a lambda (or Proc):*
+Here an example using a lambda (or Proc):
+
 
 it "should times all positions (greater than 1) by 2" do
   result = @person.lists[0].items.where(:pos.gt => 1).adjust!(:pos => lambda {|e| e * 2})
@@ -59,7 +67,8 @@ end
 
 The Proc approach can in simple cases be declared using a shortcut Symbol/String approach 
 
-*Here an example using a symbol :upcase to declare that the method #upcase should be used as the mutator:*
+Here an example using a symbol :upcase to declare that the method #upcase should be used as the mutator:
+
 
   it "should upcase the name - using symbol arg" do      
     result = @person.adjust!(:name => :upcase)
@@ -67,7 +76,8 @@ The Proc approach can in simple cases be declared using a shortcut Symbol/String
   end
 
-*And using a String 'upcase' instead of a symbol:* +And using a String 'upcase' instead of a symbol: +
   it "should upcase the name - using symbol arg" do      
     result = @person.adjust!(:name => 'upcase')
@@ -75,7 +85,6 @@ The Proc approach can in simple cases be declared using a shortcut Symbol/String
   end
 
+h2. Copyright -## Copyright ## - -Copyright (c) <2010> \ No newline at end of file +Copyright (c) 2010 Kristian Mandrup \ No newline at end of file diff --git a/Rakefile b/Rakefile index 25ed661..9b432e5 100644 --- a/Rakefile +++ b/Rakefile @@ -10,48 +10,13 @@ begin gem.email = "kmandrup@gmail.com" gem.homepage = "http://github.com/kristianmandrup/mongoid_embedded_helper" gem.authors = ["Kristian Mandrup"] - gem.add_dependency "mongoid", ">= 2.0.0.beta.18" - gem.add_dependency "mongoid_adjust", ">= 0.1.1" - gem.add_dependency "bson_ext", ">= 1.0.8" + gem.add_dependency "mongoid", ">= 2.0.0.rc.7" + gem.add_dependency "mongoid_adjust", ">= 0.1.1" + gem.add_dependency "bson_ext", ">= 1.0.8" - gem.add_development_dependency "rspec", ">=2.0.1" + gem.add_development_dependency "rspec", ">= 2.4.0" end Jeweler::GemcutterTasks.new rescue LoadError puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" end -# -# require 'rake/testtask' -# Rake::TestTask.new(:test) do |test| -# test.libs << 'lib' << 'test' -# test.pattern = 'test/**/test_*.rb' -# test.verbose = true -# end -# -# begin -# require 'rcov/rcovtask' -# Rcov::RcovTask.new do |test| -# test.libs << 'test' -# test.pattern = 'test/**/test_*.rb' -# test.verbose = true -# end -# rescue LoadError -# task :rcov do -# abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov" -# end -# end -# -# task :test => :check_dependencies -# -# task :default => :test -# -# require 'rake/rdoctask' -# Rake::RDocTask.new do |rdoc| -# version = File.exist?('VERSION') ? File.read('VERSION') : "" -# -# rdoc.rdoc_dir = 'rdoc' -# rdoc.title = "mongoid_acts_as_tree #{version}" -# rdoc.rdoc_files.include('README*') -# rdoc.rdoc_files.include('lib/**/*.rb') -# end -# diff --git a/VERSION b/VERSION index 0d91a54..9e11b32 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.0 +0.3.1 diff --git a/lib/mongoid/embedded_helper.rb b/lib/mongoid/embedded_helper.rb index 7f799b4..3fc19fd 100644 --- a/lib/mongoid/embedded_helper.rb +++ b/lib/mongoid/embedded_helper.rb @@ -3,15 +3,13 @@ module Mongoid module EmbeddedHelper def self.included(model) - model.class_eval do - + model.class_eval do alias_method :old_parentize, :parentize def parentize(document) old_parentize document send(:after_parentize) if respond_to?(:after_parentize) # run_callbacks(:after_parentize) - end - + end end end