Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
991b28a
Fixed Config#from_hash to use indifferent-access, added Config#to_hash.
CodeMonkeySteve Jan 29, 2011
82ec84f
Added database_cleaner
CodeMonkeySteve Jan 29, 2011
b86e58e
Fixed spec for Time conversion.
CodeMonkeySteve Jan 29, 2011
ae682d5
Added railtie with DB rake tasks.
CodeMonkeySteve Jan 30, 2011
bd89e54
Criteria: fixed infinite-recursion by mapping enumerable methods dire…
CodeMonkeySteve Jan 30, 2011
ca81e63
Added autotest, ruby-debug. Updated gitignore.
CodeMonkeySteve Jan 31, 2011
511674e
Document: added Finders, refactored #find to take one or more ids, ad…
CodeMonkeySteve Jan 29, 2011
be1e0dc
Document: added various AR-compatibility and convenience functions, r…
CodeMonkeySteve Jan 29, 2011
5bf3a7d
Added #save! to raise error on invalid documents
CodeMonkeySteve Jan 30, 2011
32f43a3
Document#save now returns instance instead of id (warning: backward-i…
CodeMonkeySteve Jan 31, 2011
b1f00a3
Document: fixed #find when no arguments.
CodeMonkeySteve Feb 12, 2011
a3fb16c
add missing error class
Feb 16, 2011
b036820
update Mongo::Collection.new calls
Feb 16, 2011
a16a1da
before_validate callback
Feb 17, 2011
11021a8
Merge branch 'master' of https://github.com/carlosparamio/mongo_odm
CodeMonkeySteve Mar 14, 2011
dbed85d
Updated gems, added Bundler to spec_helper.
CodeMonkeySteve Mar 14, 2011
2b32742
Merge branch 'friendly'
CodeMonkeySteve Mar 15, 2011
e17dd90
Fixed code style.
CodeMonkeySteve Mar 18, 2011
c01f3b6
Refactored instanciate.
CodeMonkeySteve Mar 18, 2011
f941ed5
Refactored Document#to_dbref to Referable module.
CodeMonkeySteve Mar 18, 2011
31ff193
Added Reference type.
CodeMonkeySteve Dec 29, 2010
3bdbca6
Added spec for Timestamp.
CodeMonkeySteve Mar 24, 2011
74a08aa
Automatically include railtie if Rails defined.
CodeMonkeySteve Mar 24, 2011
1dfa2a4
Added rounding of Time value to fix serialization.
CodeMonkeySteve Mar 24, 2011
a5117c7
Fixed #sort/#skip/#limit in finders.
CodeMonkeySteve Mar 24, 2011
e102039
Document#reload now returns self.
CodeMonkeySteve Mar 24, 2011
a135c91
Document finders now properly reuse/rewind cursor.
CodeMonkeySteve Mar 24, 2011
6d6191d
Removed redundant validation from #save!.
CodeMonkeySteve Mar 24, 2011
4cc4090
Fixed Validation exception.
CodeMonkeySteve Mar 24, 2011
46df891
Refactored Criteria to construct cursor lazily and reuse, added #reload.
CodeMonkeySteve Mar 24, 2011
d0a06e6
Don't delegate Criteria#inspect.
CodeMonkeySteve Mar 24, 2011
ad0b4e5
Added #referenced_in for associations.
CodeMonkeySteve Mar 24, 2011
dd5e722
Fixed Criteria to call #to_mongo on selector.
CodeMonkeySteve Mar 25, 2011
d3f6a70
Fixed Document#find! when passed string IDs.
CodeMonkeySteve Mar 30, 2011
f5588d8
Force Reference#as_json to delegate.
CodeMonkeySteve Mar 30, 2011
1b5ce22
Merge remote-tracking branch 'carlos/master', added criteria_spec.
CodeMonkeySteve Apr 11, 2011
1903df1
Removed version specs from gem dependencies, updated mongo/bson_ext.
CodeMonkeySteve Apr 11, 2011
b7034c8
Force Reference to delegate #to_param to target.
CodeMonkeySteve May 3, 2011
b15a7ce
Minor fix for Rails 3.1.
CodeMonkeySteve Jun 7, 2011
4242d5b
Fix for Document[attr].
CodeMonkeySteve Jun 7, 2011
f925ba3
Fixed two cases of bad syntax on raising an exception.
CodeMonkeySteve Jun 8, 2011
d2a7568
Reference: delegate #id to DBRef instead of dereferencing.
CodeMonkeySteve Jun 22, 2011
f4a55fe
Fixed Criteria#count to delegate to cursor (instead of result array).
CodeMonkeySteve Jul 1, 2011
9b2f3a4
Fix for ActiveModel 3.1 API change.
CodeMonkeySteve Jul 7, 2011
bd16977
Document#find can now take an Array of IDs and returns an Array of do…
CodeMonkeySteve Jul 7, 2011
f5d2970
don't mark an attribute as dirty if it doesn't change
dusty Jul 8, 2011
3cc1abc
Merge pull request #3 from dusty/master
CodeMonkeySteve Jul 8, 2011
27a6d99
Delegate Criteria#each to cursor instead of #to_a.
CodeMonkeySteve Sep 6, 2011
341a093
track attribute_methods_generated to ensure define_attribute_methods_…
msaffitz Sep 21, 2011
ea5475a
Merge pull request #4 from msaffitz/master
CodeMonkeySteve Sep 22, 2011
f24c9d8
Fix for comparison of BSON::DBRef with nil.
CodeMonkeySteve Nov 15, 2011
9929a74
Added check to throw exception when referencing a new record.
CodeMonkeySteve Dec 7, 2011
5df2404
Replaced autotest with guard.
CodeMonkeySteve Dec 7, 2011
c27203a
Added Criteria#first (uses Collection#find_one).
CodeMonkeySteve Dec 8, 2011
d4ff72f
Moved #sort, #skip, and #limit to Criteria, added #all (alias for #wh…
CodeMonkeySteve Dec 8, 2011
ab6661a
Updated all gems (especially mongo to 1.5).
CodeMonkeySteve Dec 8, 2011
c009475
Collection delegates missing methods to Criteria (instead of a cursor…
CodeMonkeySteve Dec 8, 2011
652d8c9
Updated ruby-debug 1.9 support for 1.9.3.
CodeMonkeySteve Jan 15, 2012
7e2f6c4
Moved module instance methods to conform to new ActiveSupport::Concer…
CodeMonkeySteve May 26, 2012
e9df9ea
Changed Document.field to take type as option (compatible with Mongoid).
CodeMonkeySteve May 28, 2012
c3ad230
Fixed RSpec module name.
CodeMonkeySteve May 28, 2012
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Gemfile.lock
doc
pkg
vendor/bundle
.bundle
.rvmrc
.bundle
.kdev4
31 changes: 20 additions & 11 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
# Use `bundle install` in order to install these gems
source 'http://rubygems.org'

gem "activesupport", "~>3.0.5"
gem "activemodel", "~>3.0.5"
gem "mongo", "~>1.2.4"
gem "bson_ext", "~>1.2.4"
gem "tzinfo", "~>0.3.24"
gem 'activesupport'
gem 'activemodel'
gem 'mongo'
gem 'bson_ext'
gem 'tzinfo'

group :development do
gem 'jeweler', '~>1.5.2'
gem 'yard', '~>0.6.5'
gem 'rcov', '~>0.9.9'
gem 'rspec', '~> 2.5.0'
gem 'watchr', '~>0.7'
end
gem 'database_cleaner'
gem 'guard-rspec'
gem 'jeweler'
gem 'rcov'
gem 'rspec'
gem 'yard'
gem 'watchr'

gem 'ruby-debug', :platforms => :ruby_18
platforms :ruby_19 do
gem 'linecache19', :git => 'git://github.com/mark-moseley/linecache'
gem 'ruby-debug-base19x', '~> 0.11.30.pre4'
gem 'ruby-debug19', :require => 'ruby-debug'
end
end
116 changes: 81 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,48 +1,94 @@
GIT
remote: git://github.com/mark-moseley/linecache
revision: 869c6a65155068415925067e480741bd0a71527e
specs:
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)

GEM
remote: http://rubygems.org/
specs:
activemodel (3.0.5)
activesupport (= 3.0.5)
builder (~> 2.1.2)
i18n (~> 0.4)
activesupport (3.0.5)
bson (1.2.4)
bson_ext (1.2.4)
builder (2.1.2)
diff-lcs (1.1.2)
activemodel (3.1.3)
activesupport (= 3.1.3)
builder (~> 3.0.0)
i18n (~> 0.6)
activesupport (3.1.3)
multi_json (~> 1.0)
archive-tar-minitar (0.5.2)
bson (1.5.1)
bson_ext (1.5.1)
builder (3.0.0)
columnize (0.3.5)
database_cleaner (0.7.0)
diff-lcs (1.1.3)
git (1.2.5)
i18n (0.5.0)
jeweler (1.5.2)
bundler (~> 1.0.0)
guard (0.8.8)
thor (~> 0.14.6)
guard-rspec (0.5.9)
guard (>= 0.8.4)
i18n (0.6.0)
jeweler (1.6.4)
bundler (~> 1.0)
git (>= 1.2.5)
rake
mongo (1.2.4)
bson (>= 1.2.4)
rake (0.8.7)
rcov (0.9.9)
rspec (2.5.0)
rspec-core (~> 2.5.0)
rspec-expectations (~> 2.5.0)
rspec-mocks (~> 2.5.0)
rspec-core (2.5.1)
rspec-expectations (2.5.0)
linecache (0.46)
rbx-require-relative (> 0.0.4)
mongo (1.5.1)
bson (= 1.5.1)
multi_json (1.0.4)
rake (0.9.2.2)
rbx-require-relative (0.0.5)
rcov (0.9.11)
rspec (2.7.0)
rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0)
rspec-mocks (~> 2.7.0)
rspec-core (2.7.1)
rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.5.0)
tzinfo (0.3.24)
rspec-mocks (2.7.0)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
ruby-debug-base19 (0.11.25)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby_core_source (>= 0.1.4)
ruby-debug-base19x (0.11.30.pre4)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
rake (>= 0.8.1)
ruby_core_source (>= 0.1.4)
ruby-debug19 (0.11.6)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
thor (0.14.6)
tzinfo (0.3.31)
watchr (0.7)
yard (0.6.5)
yard (0.7.4)

PLATFORMS
ruby

DEPENDENCIES
activemodel (~> 3.0.5)
activesupport (~> 3.0.5)
bson_ext (~> 1.2.4)
jeweler (~> 1.5.2)
mongo (~> 1.2.4)
rcov (~> 0.9.9)
rspec (~> 2.5.0)
tzinfo (~> 0.3.24)
watchr (~> 0.7)
yard (~> 0.6.5)
activemodel
activesupport
bson_ext
database_cleaner
guard-rspec
jeweler
linecache19!
mongo
rcov
rspec
ruby-debug
ruby-debug-base19x (~> 0.11.30.pre4)
ruby-debug19
tzinfo
watchr
yard
7 changes: 7 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
group 'specs' do
guard 'rspec', all_after_pass: false, cli: '--color --format nested' do # --fail-fast --drb
watch(%r{(^|/)\.'}) {} # ignore dot files
watch('spec/spec_helper.rb') { 'spec' }
watch(%r{^spec/(.+)_spec\.rb})
end
end
4 changes: 2 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ By default, mongo_odm stores data on a collection with the same name than the cl
Alternatively, you can pass a MongoODM::Collection instance to set_collection, to indicate not only a collection name, but also a different connection and/or database:

class Shape
set_collection MongoODM::Collection.new(MongoODM.connection.db('another_database'), 'my_shapes')
set_collection MongoODM::Collection.new('my_shapes', MongoODM.connection.db('another_database'))
end

= References
Expand Down Expand Up @@ -457,4 +457,4 @@ See CONTRIBUTORS file for a list of contributions.

= License

See LICENSE file for details.
See LICENSE file for details.
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ if Gem.available? 'rspec'
require "rspec"
require "rspec/core/rake_task"
desc "Run all specs"
Rspec::Core::RakeTask.new(:spec) do |spec|
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = "spec/**/*_spec.rb"
end

## rcov task
if Gem.available? 'rcov'
require 'rcov/rcovtask'
Rspec::Core::RakeTask.new(:rcov) do |spec|
RSpec::Core::RakeTask.new(:rcov) do |spec|
spec.pattern = "spec/**/*_spec.rb"
spec.rcov = true
end
Expand Down Expand Up @@ -70,4 +70,4 @@ task :release => :build do
end

## default task
task :default => :spec
task :default => :spec
18 changes: 12 additions & 6 deletions lib/mongo_odm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def self.connection=(value)
end

def self.database
Thread.current[:mongo_odm_database] ||= self.connection.db( config.database )
Thread.current[:mongo_odm_database] ||= self.connection.db(config.database)
end

def self.config
Expand All @@ -40,12 +40,13 @@ def self.config=(value)
end

def self.instanciate(value)
return value if value.is_a?(MongoODM::Document)
if value.is_a?(Hash)
klass = value["_class"] || value[:_class]
return klass.constantize.new(value) if klass
if value.is_a?(MongoODM::Document) || value.is_a?(MongoODM::Reference)
value
elsif value.is_a?(Hash) && (klass = value["_class"] || value[:_class])
klass.constantize.new(value)
else
value.class.type_cast(value.to_mongo)
end
value.class.type_cast(value.to_mongo)
end

def self.dereference(value)
Expand All @@ -65,3 +66,8 @@ def self.add_index_class(klass)
end

end

if defined?(Rails)
require 'mongo_odm/railtie'
end

15 changes: 13 additions & 2 deletions lib/mongo_odm/config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/object/blank'
require 'uri'

module MongoODM
Expand All @@ -10,7 +12,7 @@ def initialize(opts = {})
@database ||= 'test'
@host ||= 'localhost'
@port || 27017
@logger ||= Rails.logger if defined?(Rails)
@logger ||= Rails.logger if defined?(Rails)
@pool_size ||= 1
end

Expand All @@ -21,7 +23,7 @@ def uri=(uri)
end

def from_hash(opts)
opts = opts.dup.symbolize_keys!
opts = opts.with_indifferent_access

if opts[:uri].present?
self.uri = opts[:uri]
Expand All @@ -34,6 +36,15 @@ def from_hash(opts)
@pool_size ||= opts[:pool_size]
end

def to_hash
conf = %w(database host port username password pool_size).map do |k|
[ k.to_sym, self.send(k.to_sym) ]
end
conf = Hash[conf]
conf.reject! { |k, v| v.nil? }
conf
end

def connection
opts = { :logger => self.logger, :pool_size => self.pool_size }
Mongo::Connection.new(self.host, self.port, opts).tap do |conn|
Expand Down
Loading