dm-core 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +19 -20
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/dm-core.gemspec +15 -12
- data/lib/dm-core.rb +23 -14
- data/lib/dm-core/adapters.rb +7 -3
- data/lib/dm-core/adapters/abstract_adapter.rb +3 -9
- data/lib/dm-core/associations/many_to_many.rb +1 -1
- data/lib/dm-core/associations/many_to_one.rb +3 -4
- data/lib/dm-core/associations/one_to_many.rb +2 -2
- data/lib/dm-core/associations/one_to_one.rb +1 -1
- data/lib/dm-core/collection.rb +4 -6
- data/lib/dm-core/model.rb +22 -32
- data/lib/dm-core/model/property.rb +15 -39
- data/lib/dm-core/property.rb +75 -87
- data/lib/dm-core/property/discriminator.rb +3 -3
- data/lib/dm-core/property/lookup.rb +42 -0
- data/lib/dm-core/property/object.rb +5 -0
- data/lib/dm-core/property/serial.rb +6 -1
- data/lib/dm-core/query/conditions/comparison.rb +3 -3
- data/lib/dm-core/query/conditions/operation.rb +3 -3
- data/lib/dm-core/resource.rb +2 -2
- data/lib/dm-core/resource/state/dirty.rb +2 -2
- data/lib/dm-core/spec/lib/spec_helper.rb +11 -3
- data/lib/dm-core/spec/setup.rb +2 -2
- data/{spec/public/shared/property_shared_spec.rb → lib/dm-core/spec/shared/public/property_spec.rb} +51 -20
- data/{spec/semipublic/shared/property_shared_spec.rb → lib/dm-core/spec/shared/semipublic/property_spec.rb} +22 -26
- data/lib/dm-core/support/descendant_set.rb +84 -0
- data/lib/dm-core/support/naming_conventions.rb +8 -8
- data/lib/dm-core/types/discriminator.rb +2 -2
- data/spec/public/associations/many_to_one_with_custom_fk_spec.rb +49 -0
- data/spec/public/finalize_spec.rb +42 -11
- data/spec/public/property/discriminator_spec.rb +6 -6
- data/spec/semipublic/adapters/abstract_adapter_spec.rb +1 -1
- data/spec/semipublic/property/lookup_spec.rb +26 -0
- data/spec/semipublic/property_spec.rb +43 -0
- data/spec/semipublic/resource/state/dirty_spec.rb +4 -2
- data/spec/support/{types → properties}/huge_integer.rb +5 -5
- data/tasks/local_gemfile.rake +5 -7
- metadata +15 -19
- data/lib/dm-core/model/descendant_set.rb +0 -81
@@ -1,81 +0,0 @@
|
|
1
|
-
module DataMapper
|
2
|
-
module Model
|
3
|
-
class DescendantSet
|
4
|
-
include Enumerable
|
5
|
-
|
6
|
-
# Append a model as a descendant
|
7
|
-
#
|
8
|
-
# @param [Model] model
|
9
|
-
# the descendant model
|
10
|
-
#
|
11
|
-
# @return [DescendantSet]
|
12
|
-
# self
|
13
|
-
#
|
14
|
-
# @api private
|
15
|
-
def <<(model)
|
16
|
-
@descendants << model unless @descendants.include?(model)
|
17
|
-
@ancestors << model if @ancestors
|
18
|
-
self
|
19
|
-
end
|
20
|
-
|
21
|
-
# Iterate over each descendant
|
22
|
-
#
|
23
|
-
# @yield [model]
|
24
|
-
# iterate over each descendant
|
25
|
-
# @yieldparam [Model] model
|
26
|
-
# the descendant model
|
27
|
-
#
|
28
|
-
# @return [DescendantSet]
|
29
|
-
# self
|
30
|
-
#
|
31
|
-
# @api private
|
32
|
-
def each
|
33
|
-
@descendants.each { |model| yield model }
|
34
|
-
self
|
35
|
-
end
|
36
|
-
|
37
|
-
# Remove a descendant
|
38
|
-
#
|
39
|
-
# Also removed the descendant from the ancestors.
|
40
|
-
#
|
41
|
-
# @param [Model] model
|
42
|
-
# the model to remove
|
43
|
-
#
|
44
|
-
# @return [Model, nil]
|
45
|
-
# the model is return if it is a descendant
|
46
|
-
#
|
47
|
-
# @api private
|
48
|
-
def delete(model)
|
49
|
-
@ancestors.delete(model) if @ancestors
|
50
|
-
@descendants.delete(model)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Return an Array representation of descendants
|
54
|
-
#
|
55
|
-
# @return [Array]
|
56
|
-
# the descendants
|
57
|
-
#
|
58
|
-
# @api private
|
59
|
-
def to_ary
|
60
|
-
@descendants.dup
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
# Initialize a DescendantSet instance
|
66
|
-
#
|
67
|
-
# @param [Model] model
|
68
|
-
# the base model
|
69
|
-
# @param [DescendantSet] ancestors
|
70
|
-
# the ancestors to notify when a descendant is added
|
71
|
-
#
|
72
|
-
# @api private
|
73
|
-
def initialize(model = nil, ancestors = nil)
|
74
|
-
@descendants = []
|
75
|
-
@ancestors = ancestors
|
76
|
-
|
77
|
-
@descendants << model if model
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|