mongomodel 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -30,7 +30,7 @@ begin
30
30
  Jeweler::Tasks.new do |gem|
31
31
  gem.name = "mongomodel"
32
32
  gem.summary = "MongoDB ORM for Ruby/Rails"
33
- gem.description = "MongoModel is a MongoDB ORM for Ruby/Rails similar to ActiveRecord, DataMapper."
33
+ gem.description = "MongoModel is a MongoDB ORM for Ruby/Rails similar to ActiveRecord and DataMapper."
34
34
  gem.email = "sam@sampohlenz.com"
35
35
  gem.homepage = "http://github.com/spohlenz/mongomodel"
36
36
  gem.authors = ["Sam Pohlenz"]
@@ -1,5 +1,4 @@
1
1
  require 'active_support/core_ext/module/aliasing'
2
- require 'active_support/core_ext/class/removal'
3
2
 
4
3
  module MongoModel
5
4
  module Attributes
@@ -5,7 +5,7 @@ module MongoModel
5
5
 
6
6
  included do
7
7
  undef_method :id if method_defined?(:id)
8
- property :id, String, :as => '_id', :default => lambda { ::Mongo::ObjectID.new.to_s }
8
+ property :id, String, :as => '_id', :default => lambda { |doc| doc.generate_id }
9
9
 
10
10
  class_inheritable_writer :collection_name
11
11
  end
@@ -50,6 +50,10 @@ module MongoModel
50
50
  self.class.database
51
51
  end
52
52
 
53
+ def generate_id
54
+ ::Mongo::ObjectID.new.to_s
55
+ end
56
+
53
57
  module ClassMethods
54
58
  def create(attributes={}, &block)
55
59
  if attributes.is_a?(Array)
@@ -8,3 +8,53 @@ class Symbol
8
8
  define_method(:asc) { MongoModel::MongoOrder::Clause.new(self, :ascending) }
9
9
  define_method(:desc) { MongoModel::MongoOrder::Clause.new(self, :descending) }
10
10
  end
11
+
12
+ class Object
13
+ begin
14
+ ObjectSpace.each_object(Class.new) {}
15
+
16
+ # Exclude this class unless it's a subclass of our supers and is defined.
17
+ # We check defined? in case we find a removed class that has yet to be
18
+ # garbage collected. This also fails for anonymous classes -- please
19
+ # submit a patch if you have a workaround.
20
+ def subclasses_of(*superclasses) #:nodoc:
21
+ subclasses = []
22
+
23
+ superclasses.each do |sup|
24
+ ObjectSpace.each_object(class << sup; self; end) do |k|
25
+ if k != sup && (k.name.blank? || eval("defined?(::#{k}) && ::#{k}.object_id == k.object_id"))
26
+ subclasses << k
27
+ end
28
+ end
29
+ end
30
+
31
+ subclasses
32
+ end
33
+ rescue RuntimeError
34
+ # JRuby and any implementations which cannot handle the objectspace traversal
35
+ # above fall back to this implementation
36
+ def subclasses_of(*superclasses) #:nodoc:
37
+ subclasses = []
38
+
39
+ superclasses.each do |sup|
40
+ ObjectSpace.each_object(Class) do |k|
41
+ if superclasses.any? { |superclass| k < superclass } &&
42
+ (k.name.blank? || eval("defined?(::#{k}) && ::#{k}.object_id == k.object_id"))
43
+ subclasses << k
44
+ end
45
+ end
46
+ subclasses.uniq!
47
+ end
48
+ subclasses
49
+ end
50
+ end
51
+ end
52
+
53
+ class Class
54
+ # Returns an array with the names of the subclasses of +self+ as strings.
55
+ #
56
+ # Integer.subclasses # => ["Bignum", "Fixnum"]
57
+ def subclasses
58
+ Object.subclasses_of(self).map { |o| o.to_s }
59
+ end
60
+ end
@@ -1,3 +1,3 @@
1
1
  module MongoModel
2
- VERSION = "0.1"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -10,7 +10,7 @@ module MongoModel
10
10
  property = Document.properties[:id]
11
11
  property.name.should == :id
12
12
  property.as.should == '_id'
13
- property.default(mock('instance')).should_not be_nil
13
+ property.default(mock('instance', :generate_id => 'abc-123')).should == 'abc-123'
14
14
  end
15
15
 
16
16
  describe "single collection inheritance" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongomodel
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.1"
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Pohlenz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-27 00:00:00 +10:30
12
+ date: 2010-01-28 00:00:00 +10:30
13
13
  default_executable: console
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -42,7 +42,7 @@ dependencies:
42
42
  - !ruby/object:Gem::Version
43
43
  version: 0.18.3
44
44
  version:
45
- description: MongoModel is a MongoDB ORM for Ruby/Rails similar to ActiveRecord, DataMapper.
45
+ description: MongoModel is a MongoDB ORM for Ruby/Rails similar to ActiveRecord and DataMapper.
46
46
  email: sam@sampohlenz.com
47
47
  executables:
48
48
  - console