dm-core 0.9.11 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/.autotest +17 -14
  2. data/.gitignore +3 -1
  3. data/FAQ +6 -5
  4. data/History.txt +5 -50
  5. data/Manifest.txt +66 -76
  6. data/QUICKLINKS +1 -1
  7. data/README.txt +21 -15
  8. data/Rakefile +6 -7
  9. data/SPECS +2 -29
  10. data/TODO +1 -1
  11. data/deps.rip +2 -0
  12. data/dm-core.gemspec +11 -15
  13. data/lib/dm-core.rb +105 -110
  14. data/lib/dm-core/adapters.rb +135 -16
  15. data/lib/dm-core/adapters/abstract_adapter.rb +251 -181
  16. data/lib/dm-core/adapters/data_objects_adapter.rb +482 -534
  17. data/lib/dm-core/adapters/in_memory_adapter.rb +90 -69
  18. data/lib/dm-core/adapters/mysql_adapter.rb +22 -115
  19. data/lib/dm-core/adapters/oracle_adapter.rb +249 -0
  20. data/lib/dm-core/adapters/postgres_adapter.rb +7 -173
  21. data/lib/dm-core/adapters/sqlite3_adapter.rb +4 -97
  22. data/lib/dm-core/adapters/yaml_adapter.rb +116 -0
  23. data/lib/dm-core/associations/many_to_many.rb +372 -90
  24. data/lib/dm-core/associations/many_to_one.rb +220 -73
  25. data/lib/dm-core/associations/one_to_many.rb +319 -255
  26. data/lib/dm-core/associations/one_to_one.rb +66 -53
  27. data/lib/dm-core/associations/relationship.rb +561 -156
  28. data/lib/dm-core/collection.rb +1101 -379
  29. data/lib/dm-core/core_ext/kernel.rb +12 -0
  30. data/lib/dm-core/core_ext/symbol.rb +10 -0
  31. data/lib/dm-core/identity_map.rb +4 -34
  32. data/lib/dm-core/migrations.rb +1283 -0
  33. data/lib/dm-core/model.rb +570 -369
  34. data/lib/dm-core/model/descendant_set.rb +81 -0
  35. data/lib/dm-core/model/hook.rb +45 -0
  36. data/lib/dm-core/model/is.rb +32 -0
  37. data/lib/dm-core/model/property.rb +247 -0
  38. data/lib/dm-core/model/relationship.rb +335 -0
  39. data/lib/dm-core/model/scope.rb +90 -0
  40. data/lib/dm-core/property.rb +808 -273
  41. data/lib/dm-core/property_set.rb +141 -98
  42. data/lib/dm-core/query.rb +1037 -483
  43. data/lib/dm-core/query/conditions/comparison.rb +872 -0
  44. data/lib/dm-core/query/conditions/operation.rb +221 -0
  45. data/lib/dm-core/query/direction.rb +43 -0
  46. data/lib/dm-core/query/operator.rb +84 -0
  47. data/lib/dm-core/query/path.rb +138 -0
  48. data/lib/dm-core/query/sort.rb +45 -0
  49. data/lib/dm-core/repository.rb +210 -94
  50. data/lib/dm-core/resource.rb +641 -421
  51. data/lib/dm-core/spec/adapter_shared_spec.rb +294 -0
  52. data/lib/dm-core/spec/data_objects_adapter_shared_spec.rb +106 -0
  53. data/lib/dm-core/support/chainable.rb +22 -0
  54. data/lib/dm-core/support/deprecate.rb +12 -0
  55. data/lib/dm-core/support/logger.rb +13 -0
  56. data/lib/dm-core/{naming_conventions.rb → support/naming_conventions.rb} +6 -6
  57. data/lib/dm-core/transaction.rb +333 -92
  58. data/lib/dm-core/type.rb +98 -60
  59. data/lib/dm-core/types/boolean.rb +1 -1
  60. data/lib/dm-core/types/discriminator.rb +34 -20
  61. data/lib/dm-core/types/object.rb +7 -4
  62. data/lib/dm-core/types/paranoid_boolean.rb +11 -9
  63. data/lib/dm-core/types/paranoid_datetime.rb +11 -9
  64. data/lib/dm-core/types/serial.rb +3 -3
  65. data/lib/dm-core/types/text.rb +3 -4
  66. data/lib/dm-core/version.rb +1 -1
  67. data/script/performance.rb +102 -109
  68. data/script/profile.rb +169 -38
  69. data/spec/lib/adapter_helpers.rb +105 -0
  70. data/spec/lib/collection_helpers.rb +18 -0
  71. data/spec/lib/counter_adapter.rb +34 -0
  72. data/spec/lib/pending_helpers.rb +27 -0
  73. data/spec/lib/rspec_immediate_feedback_formatter.rb +53 -0
  74. data/spec/public/associations/many_to_many_spec.rb +193 -0
  75. data/spec/public/associations/many_to_one_spec.rb +73 -0
  76. data/spec/public/associations/one_to_many_spec.rb +77 -0
  77. data/spec/public/associations/one_to_one_spec.rb +156 -0
  78. data/spec/public/collection_spec.rb +65 -0
  79. data/spec/public/migrations_spec.rb +359 -0
  80. data/spec/public/model/relationship_spec.rb +924 -0
  81. data/spec/public/model_spec.rb +159 -0
  82. data/spec/public/property_spec.rb +829 -0
  83. data/spec/public/resource_spec.rb +71 -0
  84. data/spec/public/sel_spec.rb +44 -0
  85. data/spec/public/setup_spec.rb +145 -0
  86. data/spec/public/shared/association_collection_shared_spec.rb +317 -0
  87. data/spec/public/shared/collection_shared_spec.rb +1670 -0
  88. data/spec/public/shared/finder_shared_spec.rb +1619 -0
  89. data/spec/public/shared/resource_shared_spec.rb +924 -0
  90. data/spec/public/shared/sel_shared_spec.rb +112 -0
  91. data/spec/public/transaction_spec.rb +129 -0
  92. data/spec/public/types/discriminator_spec.rb +130 -0
  93. data/spec/semipublic/adapters/abstract_adapter_spec.rb +30 -0
  94. data/spec/semipublic/adapters/in_memory_adapter_spec.rb +12 -0
  95. data/spec/semipublic/adapters/mysql_adapter_spec.rb +17 -0
  96. data/spec/semipublic/adapters/oracle_adapter_spec.rb +194 -0
  97. data/spec/semipublic/adapters/postgres_adapter_spec.rb +17 -0
  98. data/spec/semipublic/adapters/sqlite3_adapter_spec.rb +17 -0
  99. data/spec/semipublic/adapters/yaml_adapter_spec.rb +12 -0
  100. data/spec/semipublic/associations/many_to_one_spec.rb +53 -0
  101. data/spec/semipublic/associations/relationship_spec.rb +194 -0
  102. data/spec/semipublic/associations_spec.rb +177 -0
  103. data/spec/semipublic/collection_spec.rb +142 -0
  104. data/spec/semipublic/property_spec.rb +61 -0
  105. data/spec/semipublic/query/conditions_spec.rb +528 -0
  106. data/spec/semipublic/query/path_spec.rb +443 -0
  107. data/spec/semipublic/query_spec.rb +2626 -0
  108. data/spec/semipublic/resource_spec.rb +47 -0
  109. data/spec/semipublic/shared/condition_shared_spec.rb +9 -0
  110. data/spec/semipublic/shared/resource_shared_spec.rb +126 -0
  111. data/spec/spec.opts +3 -1
  112. data/spec/spec_helper.rb +80 -57
  113. data/tasks/ci.rb +19 -31
  114. data/tasks/dm.rb +43 -48
  115. data/tasks/doc.rb +8 -11
  116. data/tasks/gemspec.rb +5 -5
  117. data/tasks/hoe.rb +15 -16
  118. data/tasks/install.rb +8 -10
  119. metadata +74 -111
  120. data/lib/dm-core/associations.rb +0 -207
  121. data/lib/dm-core/associations/relationship_chain.rb +0 -81
  122. data/lib/dm-core/auto_migrations.rb +0 -105
  123. data/lib/dm-core/dependency_queue.rb +0 -32
  124. data/lib/dm-core/hook.rb +0 -11
  125. data/lib/dm-core/is.rb +0 -16
  126. data/lib/dm-core/logger.rb +0 -232
  127. data/lib/dm-core/migrations/destructive_migrations.rb +0 -17
  128. data/lib/dm-core/migrator.rb +0 -29
  129. data/lib/dm-core/scope.rb +0 -58
  130. data/lib/dm-core/support.rb +0 -7
  131. data/lib/dm-core/support/array.rb +0 -13
  132. data/lib/dm-core/support/assertions.rb +0 -8
  133. data/lib/dm-core/support/errors.rb +0 -23
  134. data/lib/dm-core/support/kernel.rb +0 -11
  135. data/lib/dm-core/support/symbol.rb +0 -41
  136. data/lib/dm-core/type_map.rb +0 -80
  137. data/lib/dm-core/types.rb +0 -19
  138. data/script/all +0 -4
  139. data/spec/integration/association_spec.rb +0 -1382
  140. data/spec/integration/association_through_spec.rb +0 -203
  141. data/spec/integration/associations/many_to_many_spec.rb +0 -449
  142. data/spec/integration/associations/many_to_one_spec.rb +0 -163
  143. data/spec/integration/associations/one_to_many_spec.rb +0 -188
  144. data/spec/integration/auto_migrations_spec.rb +0 -413
  145. data/spec/integration/collection_spec.rb +0 -1073
  146. data/spec/integration/data_objects_adapter_spec.rb +0 -32
  147. data/spec/integration/dependency_queue_spec.rb +0 -46
  148. data/spec/integration/model_spec.rb +0 -197
  149. data/spec/integration/mysql_adapter_spec.rb +0 -85
  150. data/spec/integration/postgres_adapter_spec.rb +0 -731
  151. data/spec/integration/property_spec.rb +0 -253
  152. data/spec/integration/query_spec.rb +0 -514
  153. data/spec/integration/repository_spec.rb +0 -61
  154. data/spec/integration/resource_spec.rb +0 -513
  155. data/spec/integration/sqlite3_adapter_spec.rb +0 -352
  156. data/spec/integration/sti_spec.rb +0 -273
  157. data/spec/integration/strategic_eager_loading_spec.rb +0 -156
  158. data/spec/integration/transaction_spec.rb +0 -75
  159. data/spec/integration/type_spec.rb +0 -275
  160. data/spec/lib/logging_helper.rb +0 -18
  161. data/spec/lib/mock_adapter.rb +0 -27
  162. data/spec/lib/model_loader.rb +0 -100
  163. data/spec/lib/publicize_methods.rb +0 -28
  164. data/spec/models/content.rb +0 -16
  165. data/spec/models/vehicles.rb +0 -34
  166. data/spec/models/zoo.rb +0 -48
  167. data/spec/unit/adapters/abstract_adapter_spec.rb +0 -133
  168. data/spec/unit/adapters/adapter_shared_spec.rb +0 -15
  169. data/spec/unit/adapters/data_objects_adapter_spec.rb +0 -632
  170. data/spec/unit/adapters/in_memory_adapter_spec.rb +0 -98
  171. data/spec/unit/adapters/postgres_adapter_spec.rb +0 -133
  172. data/spec/unit/associations/many_to_many_spec.rb +0 -32
  173. data/spec/unit/associations/many_to_one_spec.rb +0 -159
  174. data/spec/unit/associations/one_to_many_spec.rb +0 -393
  175. data/spec/unit/associations/one_to_one_spec.rb +0 -7
  176. data/spec/unit/associations/relationship_spec.rb +0 -71
  177. data/spec/unit/associations_spec.rb +0 -242
  178. data/spec/unit/auto_migrations_spec.rb +0 -111
  179. data/spec/unit/collection_spec.rb +0 -182
  180. data/spec/unit/data_mapper_spec.rb +0 -35
  181. data/spec/unit/identity_map_spec.rb +0 -126
  182. data/spec/unit/is_spec.rb +0 -80
  183. data/spec/unit/migrator_spec.rb +0 -33
  184. data/spec/unit/model_spec.rb +0 -321
  185. data/spec/unit/naming_conventions_spec.rb +0 -36
  186. data/spec/unit/property_set_spec.rb +0 -90
  187. data/spec/unit/property_spec.rb +0 -753
  188. data/spec/unit/query_spec.rb +0 -571
  189. data/spec/unit/repository_spec.rb +0 -93
  190. data/spec/unit/resource_spec.rb +0 -649
  191. data/spec/unit/scope_spec.rb +0 -142
  192. data/spec/unit/transaction_spec.rb +0 -493
  193. data/spec/unit/type_map_spec.rb +0 -114
  194. data/spec/unit/type_spec.rb +0 -119
@@ -6,109 +6,144 @@ module DataMapper
6
6
  # and therefore is responsible for providing those methods.
7
7
  #
8
8
  # To see complete list of supported types, see documentation for
9
- # DataMapper::Property::TYPES
9
+ # Property::PRIMITIVES. dm-types library provides less common
10
+ # types such as ip address, uuid, json, yaml, uri, slug, version,
11
+ # file path, bcrypt hash and so forth.
10
12
  #
11
13
  # == Defining new Types
12
14
  # To define a new type, subclass DataMapper::Type, pick ruby primitive, and
13
15
  # set the options for this type.
14
16
  #
15
- # class MyType < DataMapper::Type
16
- # primitive String
17
- # size 10
17
+ # class LowerCase < DataMapper::Type
18
+ # primitive String
19
+ # auto_validation true
20
+ # length 255
18
21
  # end
19
22
  #
20
- # Following this, you will be able to use MyType as a type for any given
23
+ # Following this, you will be able to use LowerCase as a type for any given
21
24
  # property. If special materialization and serialization is required,
22
25
  # override the class methods
23
26
  #
24
- # class MyType < DataMapper::Type
25
- # primitive String
26
- # size 10
27
+ # class LowerCase < DataMapper::Type
28
+ # primitive String
29
+ # auto_validation true
30
+ # length 255
27
31
  #
28
32
  # def self.dump(value, property)
29
- # <work some magic>
33
+ # return nil unless value
34
+ # value.to_s.downcase
30
35
  # end
31
36
  #
32
37
  # def self.load(value)
33
- # <work some magic>
38
+ # value
34
39
  # end
35
40
  # end
41
+ #
42
+ # Properties of LowerCase type now will downcase it's values before
43
+ # it is persisted to the storage.
44
+ #
45
+ # One more real world example from dm-types library is a JSON type
46
+ # that stores values serialized as JSON, and often useful for embedded
47
+ # values:
48
+ #
49
+ #
50
+ # module DataMapper
51
+ # module Types
52
+ # class Json < DataMapper::Type
53
+ # primitive String
54
+ # length 65535
55
+ # lazy true
56
+ #
57
+ # def self.load(value, property)
58
+ # if value.nil?
59
+ # nil
60
+ # elsif value.kind_of?(String)
61
+ # ::JSON.load(value)
62
+ # else
63
+ # raise ArgumentError, '+value+ of a property of JSON type must be nil or a String'
64
+ # end
65
+ # end
66
+ #
67
+ # def self.dump(value, property)
68
+ # if value.nil? || value.kind_of?(String)
69
+ # value
70
+ # else
71
+ # ::JSON.dump(value)
72
+ # end
73
+ # end
74
+ #
75
+ # def self.typecast(value, property)
76
+ # if value.nil? || value.kind_of?(Array) || value.kind_of?(Hash)
77
+ # value
78
+ # else
79
+ # ::JSON.load(value.to_s)
80
+ # end
81
+ # end
82
+ # end # class Json
83
+ # JSON = Json
84
+ # end # module Types
85
+ # end # module DataMapper
36
86
  class Type
87
+
88
+ # Until cooperation of Property and Type does not change, each must
89
+ # have a separate list of options, because plugins (ex.: dm-validations)
90
+ # may want to extend one or the other, and expects no side effects
37
91
  PROPERTY_OPTIONS = [
38
92
  :accessor, :reader, :writer,
39
93
  :lazy, :default, :nullable, :key, :serial, :field, :size, :length,
40
- :format, :index, :unique_index, :check, :ordinal, :auto_validation,
41
- :validates, :unique, :track, :precision, :scale
94
+ :format, :index, :unique_index, :auto_validation,
95
+ :validates, :unique, :precision, :scale, :min, :max
42
96
  ]
43
97
 
44
- PROPERTY_OPTION_ALIASES = {
45
- :size => [ :length ]
46
- }
47
-
48
98
  class << self
49
99
 
100
+ # TODO: document
101
+ # @api private
50
102
  def configure(primitive_type, options)
103
+ warn "DataMapper.Type.configure is deprecated, specify the primitive and options explicitly (#{caller[0]})"
104
+
51
105
  @_primitive_type = primitive_type
52
106
  @_options = options
53
107
 
54
108
  def self.inherited(base)
55
109
  base.primitive @_primitive_type
56
-
57
- @_options.each do |k, v|
58
- base.send(k, v)
59
- end
110
+ @_options.each { |key, value| base.send(key, value) }
60
111
  end
61
112
 
62
113
  self
63
114
  end
64
115
 
65
- # The Ruby primitive type to use as basis for this type. See
66
- # DataMapper::Property::TYPES for list of types.
116
+ # Ruby primitive type to use as basis for this type. See
117
+ # Property::PRIMITIVES for list of types.
67
118
  #
68
- # @param primitive<Class, nil>
119
+ # @param primitive [Class, nil]
69
120
  # The class for the primitive. If nil is passed in, it returns the
70
121
  # current primitive
71
122
  #
72
- # @return <Class> if the <primitive> param is nil, return the current primitive.
123
+ # @return [Class] if the <primitive> param is nil, return the current primitive.
73
124
  #
74
125
  # @api public
75
126
  def primitive(primitive = nil)
76
127
  return @primitive if primitive.nil?
77
-
78
- # TODO: change Integer to be used internally once most in-the-wild code
79
- # is updated to use Integer for properties instead of Fixnum, or before
80
- # DM 1.0, whichever comes first
81
- if Fixnum == primitive
82
- warn "#{primitive} properties are deprecated. Please use Integer instead"
83
- primitive = Integer
84
- end
85
-
86
128
  @primitive = primitive
87
129
  end
88
130
 
89
- # Load DataMapper::Property options
131
+ # Load Property options
90
132
  PROPERTY_OPTIONS.each do |property_option|
91
- self.class_eval <<-EOS, __FILE__, __LINE__
92
- def #{property_option}(arg = nil)
93
- return @#{property_option} if arg.nil?
94
-
95
- @#{property_option} = arg
96
- end
97
- EOS
98
- end
99
-
100
- # Create property aliases
101
- PROPERTY_OPTION_ALIASES.each do |property_option, aliases|
102
- aliases.each do |ali|
103
- self.class_eval <<-EOS, __FILE__, __LINE__
104
- alias #{ali} #{property_option}
105
- EOS
106
- end
133
+ self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
134
+ def #{property_option}(*args) # def unique(*args)
135
+ if args.any? # if args.any?
136
+ @#{property_option} = args.first # @unique = args.first
137
+ else # else
138
+ defined?(@#{property_option}) ? @#{property_option} : nil # defined?(@unique) ? @unique : nil
139
+ end # end
140
+ end # end
141
+ RUBY
107
142
  end
108
143
 
109
144
  # Gives all the options set on this type
110
145
  #
111
- # @return <Hash> with all options and their values set on this type
146
+ # @return [Hash] with all options and their values set on this type
112
147
  #
113
148
  # @api public
114
149
  def options
@@ -123,10 +158,10 @@ module DataMapper
123
158
 
124
159
  # Stub instance method for dumping
125
160
  #
126
- # @param value<Object, nil> the value to dump
127
- # @param property<Property, nil> the property the type is being used by
161
+ # @param value [Object, nil] value to dump
162
+ # @param property [Property, nil] property the type is being used by
128
163
  #
129
- # @return <Object> Dumped object
164
+ # @return [Object] Dumped object
130
165
  #
131
166
  # @api public
132
167
  def self.dump(value, property)
@@ -135,25 +170,28 @@ module DataMapper
135
170
 
136
171
  # Stub instance method for loading
137
172
  #
138
- # @param value<Object, nil> the value to serialize
139
- # @param property<Property, nil> the property the type is being used by
173
+ # @param value [Object, nil] value to serialize
174
+ # @param property [Property, nil] property the type is being used by
140
175
  #
141
- # @return <Object> Serialized object. Must be the same type as the Ruby primitive
176
+ # @return [Object] Serialized object. Must be the same type as the Ruby primitive
142
177
  #
143
178
  # @api public
144
179
  def self.load(value, property)
145
180
  value
146
181
  end
147
182
 
183
+ # A hook to allow types to extend or modify property it's bound to.
184
+ # Implementations are not supposed to modify the state of the type class, and
185
+ # should produce no side-effects on the type class.
148
186
  def self.bind(property)
149
- # This method should not modify the state of this type class, and
150
- # should produce no side-effects on the type class. It's just a
151
- # hook to allow your custom-type to modify the property it's bound to.
187
+ # no op
152
188
  end
153
189
 
154
190
  end # class Type
155
191
 
192
+ # @deprecated
156
193
  def self.Type(primitive_type, options = {})
194
+ warn "DataMapper.Type(#{primitive_type}) is deprecated, specify the primitive and options explicitly (#{caller[0]})"
157
195
  Class.new(Type).configure(primitive_type, options)
158
196
  end
159
197
 
@@ -1,6 +1,6 @@
1
1
  module DataMapper
2
2
  module Types
3
- class Boolean < DataMapper::Type
3
+ class Boolean < Type
4
4
  primitive TrueClass
5
5
  end # class Boolean
6
6
  end # module Types
@@ -1,33 +1,47 @@
1
1
  module DataMapper
2
2
  module Types
3
- class Discriminator < DataMapper::Type
3
+ class Discriminator < Type
4
4
  primitive Class
5
- track :set
6
- default lambda { |r,p| p.model }
7
- nullable false
5
+ default lambda { |resource, property| resource.model }
6
+ nullable false
8
7
 
8
+ # TODO: document
9
+ # @api private
9
10
  def self.bind(property)
10
- model = property.model
11
+ repository_name = property.repository_name
12
+ model = property.model
11
13
 
12
- model.class_eval <<-EOS, __FILE__, __LINE__
13
- def self.descendants
14
- (@descendants ||= []).uniq!
15
- @descendants
16
- end
14
+ model.default_scope(repository_name).update(property.name => model.descendants)
17
15
 
18
- after_class_method :inherited, :add_scope_for_discriminator
16
+ model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
17
+ extend Chainable
19
18
 
20
- def self.add_scope_for_discriminator(retval, target)
21
- target.descendants << target
22
- target.default_scope.update(#{property.name.inspect} => target.descendants)
23
- propagate_descendants(target)
24
- end
19
+ extendable do
20
+ def inherited(model)
21
+ super # setup self.descendants
22
+ set_discriminator_scope_for(model)
23
+ end
24
+
25
+ def new(*args, &block)
26
+ if args.size == 1 && args.first.kind_of?(Hash)
27
+ discriminator = properties(repository_name).discriminator
28
+ model = discriminator.typecast(args.first[discriminator.name])
29
+
30
+ if model.kind_of?(Model) && !model.equal?(self)
31
+ return model.new(*args, &block)
32
+ end
33
+ end
34
+
35
+ super
36
+ end
37
+
38
+ private
25
39
 
26
- def self.propagate_descendants(target)
27
- descendants << target
28
- superclass.propagate_descendants(target) if superclass.respond_to?(:propagate_descendants)
40
+ def set_discriminator_scope_for(model)
41
+ model.default_scope(#{repository_name.inspect}).update(#{property.name.inspect} => model.descendants)
42
+ end
29
43
  end
30
- EOS
44
+ RUBY
31
45
  end
32
46
  end # class Discriminator
33
47
  end # module Types
@@ -1,21 +1,24 @@
1
- require "base64"
2
-
3
1
  module DataMapper
4
2
  module Types
5
- class Object < DataMapper::Type
3
+ class Object < Type
6
4
  primitive String
7
5
  size 65535
8
6
  lazy true
9
- track :hash
10
7
 
8
+ # TODO: document
9
+ # @api private
11
10
  def self.typecast(value, property)
12
11
  value
13
12
  end
14
13
 
14
+ # TODO: document
15
+ # @api private
15
16
  def self.dump(value, property)
16
17
  Base64.encode64(Marshal.dump(value))
17
18
  end
18
19
 
20
+ # TODO: document
21
+ # @api private
19
22
  def self.load(value, property)
20
23
  value.nil? ? nil : Marshal.load(Base64.decode64(value))
21
24
  end
@@ -1,20 +1,22 @@
1
1
  module DataMapper
2
2
  module Types
3
- class ParanoidBoolean < DataMapper::Type(Boolean)
3
+ class ParanoidBoolean < Type
4
4
  primitive TrueClass
5
5
  default false
6
6
  lazy true
7
7
 
8
+ # TODO: document
9
+ # @api private
8
10
  def self.bind(property)
9
- model = property.model
10
- repository = property.repository
11
+ repository_name = property.repository_name
12
+ model = property.model
13
+ property_name = property.name
11
14
 
12
- model.send(:set_paranoid_property, property.name){true}
13
-
14
- model.class_eval <<-EOS, __FILE__, __LINE__
15
+ model.send(:set_paranoid_property, property_name){true}
15
16
 
17
+ model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
16
18
  def self.with_deleted
17
- with_exclusive_scope(#{property.name.inspect} => true) do
19
+ with_exclusive_scope(#{property_name.inspect} => true) do
18
20
  yield
19
21
  end
20
22
  end
@@ -25,9 +27,9 @@ module DataMapper
25
27
  end
26
28
  save
27
29
  end
28
- EOS
30
+ RUBY
29
31
 
30
- model.default_scope(repository.name).update(property.name => false)
32
+ model.default_scope(repository_name).update(property_name => false)
31
33
  end
32
34
  end # class ParanoidBoolean
33
35
  end # module Types
@@ -1,19 +1,21 @@
1
1
  module DataMapper
2
2
  module Types
3
- class ParanoidDateTime < DataMapper::Type(DateTime)
3
+ class ParanoidDateTime < Type
4
4
  primitive DateTime
5
5
  lazy true
6
6
 
7
+ # TODO: document
8
+ # @api private
7
9
  def self.bind(property)
8
- model = property.model
9
- repository = property.repository
10
+ repository_name = property.repository_name
11
+ model = property.model
12
+ property_name = property.name
10
13
 
11
- model.send(:set_paranoid_property, property.name){DateTime.now}
12
-
13
- model.class_eval <<-EOS, __FILE__, __LINE__
14
+ model.send(:set_paranoid_property, property_name){DateTime.now}
14
15
 
16
+ model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
15
17
  def self.with_deleted
16
- with_exclusive_scope(#{property.name.inspect}.not => nil) do
18
+ with_exclusive_scope(#{property_name.inspect}.not => nil) do
17
19
  yield
18
20
  end
19
21
  end
@@ -24,9 +26,9 @@ module DataMapper
24
26
  end
25
27
  save
26
28
  end
27
- EOS
29
+ RUBY
28
30
 
29
- model.default_scope(repository.name).update(property.name => nil)
31
+ model.default_scope(repository_name).update(property_name => nil)
30
32
  end
31
33
  end # class ParanoidDateTime
32
34
  end # module Types
@@ -1,9 +1,9 @@
1
- # FIXME: can we alias this to the class Text if it isn't already defined?
2
1
  module DataMapper
3
2
  module Types
4
- class Serial < DataMapper::Type
3
+ class Serial < Type
5
4
  primitive Integer
6
- serial true
5
+ serial true
6
+ min 1
7
7
  end # class Text
8
8
  end # module Types
9
9
  end # module DataMapper
@@ -1,10 +1,9 @@
1
- # FIXME: can we alias this to the class Text if it isn't already defined?
2
1
  module DataMapper
3
2
  module Types
4
- class Text < DataMapper::Type
3
+ class Text < Type
5
4
  primitive String
6
- size 65535
7
- lazy true
5
+ length 65535
6
+ lazy true
8
7
  end # class Text
9
8
  end # module Types
10
9
  end # module DataMapper