mongomodel 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongomodel.rb +1 -0
- data/lib/mongomodel/concerns/associations/base/association.rb +2 -0
- data/lib/mongomodel/concerns/attributes.rb +4 -4
- data/lib/mongomodel/concerns/translation.rb +10 -0
- data/lib/mongomodel/concerns/validations.rb +0 -5
- data/lib/mongomodel/embedded_document.rb +2 -0
- data/lib/mongomodel/support/core_extensions.rb +47 -35
- data/lib/mongomodel/version.rb +1 -1
- metadata +3 -2
data/lib/mongomodel.rb
CHANGED
@@ -17,6 +17,7 @@ module MongoModel
|
|
17
17
|
autoload :Attributes, 'mongomodel/concerns/attributes'
|
18
18
|
autoload :AttributeMethods, 'mongomodel/concerns/attribute_methods'
|
19
19
|
autoload :Associations, 'mongomodel/concerns/associations'
|
20
|
+
autoload :Translation, 'mongomodel/concerns/translation'
|
20
21
|
autoload :Validations, 'mongomodel/concerns/validations'
|
21
22
|
autoload :Callbacks, 'mongomodel/concerns/callbacks'
|
22
23
|
autoload :Logging, 'mongomodel/concerns/logging'
|
@@ -69,12 +69,12 @@ module MongoModel
|
|
69
69
|
|
70
70
|
private
|
71
71
|
def class_for_type(type)
|
72
|
-
|
72
|
+
klass = type.constantize
|
73
73
|
|
74
|
-
if (subclasses + [name]).include?(type
|
75
|
-
|
74
|
+
if (subclasses + [name]).include?(type)
|
75
|
+
klass
|
76
76
|
else
|
77
|
-
raise DocumentNotFound, "Document not of the correct type (got #{type
|
77
|
+
raise DocumentNotFound, "Document not of the correct type (got #{type})"
|
78
78
|
end
|
79
79
|
rescue NameError
|
80
80
|
self
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/core_ext/object/blank'
|
2
|
+
|
1
3
|
class Boolean < TrueClass; end
|
2
4
|
|
3
5
|
class Symbol
|
@@ -9,52 +11,62 @@ class Symbol
|
|
9
11
|
define_method(:desc) { MongoModel::MongoOrder::Clause.new(self, :descending) }
|
10
12
|
end
|
11
13
|
|
12
|
-
class
|
13
|
-
|
14
|
-
|
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:
|
14
|
+
class Class
|
15
|
+
# Rubinius
|
16
|
+
if defined?(Class.__subclasses__)
|
17
|
+
def descendents
|
21
18
|
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
|
-
|
19
|
+
__subclasses__.each {|k| subclasses << k; subclasses.concat k.descendents }
|
31
20
|
subclasses
|
32
21
|
end
|
33
|
-
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
subclasses = []
|
22
|
+
else
|
23
|
+
# MRI
|
24
|
+
begin
|
25
|
+
ObjectSpace.each_object(Class.new) {}
|
38
26
|
|
39
|
-
|
27
|
+
def descendents
|
28
|
+
subclasses = []
|
29
|
+
ObjectSpace.each_object(class << self; self; end) do |k|
|
30
|
+
subclasses << k unless k == self
|
31
|
+
end
|
32
|
+
subclasses
|
33
|
+
end
|
34
|
+
# JRuby
|
35
|
+
rescue StandardError
|
36
|
+
def descendents
|
37
|
+
subclasses = []
|
40
38
|
ObjectSpace.each_object(Class) do |k|
|
41
|
-
|
42
|
-
(k.name.blank? || eval("defined?(::#{k}) && ::#{k}.object_id == k.object_id"))
|
43
|
-
subclasses << k
|
44
|
-
end
|
39
|
+
subclasses << k if k < self
|
45
40
|
end
|
46
41
|
subclasses.uniq!
|
42
|
+
subclasses
|
47
43
|
end
|
48
|
-
subclasses
|
49
44
|
end
|
50
45
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
# Integer.subclasses # => ["Bignum", "Fixnum"]
|
46
|
+
|
47
|
+
def reachable?
|
48
|
+
eval("defined?(::#{self}) && ::#{self}.equal?(self)")
|
49
|
+
end
|
50
|
+
|
57
51
|
def subclasses
|
58
52
|
Object.subclasses_of(self).map { |o| o.to_s }
|
59
53
|
end
|
60
54
|
end
|
55
|
+
|
56
|
+
class Object
|
57
|
+
def remove_subclasses_of(*superclasses) #:nodoc:
|
58
|
+
Class.remove_class(*subclasses_of(*superclasses))
|
59
|
+
end
|
60
|
+
|
61
|
+
# Exclude this class unless it's a subclass of our supers and is defined.
|
62
|
+
# We check defined? in case we find a removed class that has yet to be
|
63
|
+
# garbage collected. This also fails for anonymous classes -- please
|
64
|
+
# submit a patch if you have a workaround.
|
65
|
+
def subclasses_of(*superclasses) #:nodoc:
|
66
|
+
subclasses = []
|
67
|
+
superclasses.each do |klass|
|
68
|
+
subclasses.concat klass.descendents.select {|k| k.name.blank? || k.reachable?}
|
69
|
+
end
|
70
|
+
subclasses
|
71
|
+
end
|
72
|
+
end
|
data/lib/mongomodel/version.rb
CHANGED
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.3
|
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-
|
12
|
+
date: 2010-02-10 00:00:00 +10:30
|
13
13
|
default_executable: console
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/mongomodel/concerns/properties.rb
|
84
84
|
- lib/mongomodel/concerns/record_status.rb
|
85
85
|
- lib/mongomodel/concerns/timestamps.rb
|
86
|
+
- lib/mongomodel/concerns/translation.rb
|
86
87
|
- lib/mongomodel/concerns/validations.rb
|
87
88
|
- lib/mongomodel/concerns/validations/associated.rb
|
88
89
|
- lib/mongomodel/document.rb
|