dm-core 0.10.2 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -1
- data/Gemfile +143 -0
- data/Rakefile +9 -5
- data/VERSION +1 -1
- data/dm-core.gemspec +160 -57
- data/lib/dm-core.rb +131 -56
- data/lib/dm-core/adapters.rb +98 -14
- data/lib/dm-core/adapters/abstract_adapter.rb +24 -4
- data/lib/dm-core/adapters/in_memory_adapter.rb +7 -2
- data/lib/dm-core/associations/many_to_many.rb +19 -30
- data/lib/dm-core/associations/many_to_one.rb +58 -42
- data/lib/dm-core/associations/one_to_many.rb +33 -23
- data/lib/dm-core/associations/one_to_one.rb +27 -11
- data/lib/dm-core/associations/relationship.rb +4 -4
- data/lib/dm-core/collection.rb +23 -16
- data/lib/dm-core/core_ext/array.rb +36 -0
- data/lib/dm-core/core_ext/hash.rb +30 -0
- data/lib/dm-core/core_ext/module.rb +46 -0
- data/lib/dm-core/core_ext/object.rb +31 -0
- data/lib/dm-core/core_ext/pathname.rb +20 -0
- data/lib/dm-core/core_ext/string.rb +22 -0
- data/lib/dm-core/core_ext/try_dup.rb +44 -0
- data/lib/dm-core/model.rb +88 -27
- data/lib/dm-core/model/hook.rb +75 -18
- data/lib/dm-core/model/property.rb +50 -9
- data/lib/dm-core/model/relationship.rb +31 -31
- data/lib/dm-core/model/scope.rb +3 -3
- data/lib/dm-core/property.rb +196 -516
- data/lib/dm-core/property/binary.rb +7 -0
- data/lib/dm-core/property/boolean.rb +35 -0
- data/lib/dm-core/property/class.rb +24 -0
- data/lib/dm-core/property/date.rb +47 -0
- data/lib/dm-core/property/date_time.rb +48 -0
- data/lib/dm-core/property/decimal.rb +43 -0
- data/lib/dm-core/property/discriminator.rb +48 -0
- data/lib/dm-core/property/float.rb +24 -0
- data/lib/dm-core/property/integer.rb +32 -0
- data/lib/dm-core/property/numeric.rb +43 -0
- data/lib/dm-core/property/object.rb +32 -0
- data/lib/dm-core/property/serial.rb +8 -0
- data/lib/dm-core/property/string.rb +49 -0
- data/lib/dm-core/property/text.rb +12 -0
- data/lib/dm-core/property/time.rb +48 -0
- data/lib/dm-core/property/typecast/numeric.rb +32 -0
- data/lib/dm-core/property/typecast/time.rb +28 -0
- data/lib/dm-core/property_set.rb +10 -4
- data/lib/dm-core/query.rb +14 -37
- data/lib/dm-core/query/conditions/comparison.rb +8 -6
- data/lib/dm-core/query/conditions/operation.rb +33 -2
- data/lib/dm-core/query/operator.rb +2 -5
- data/lib/dm-core/query/path.rb +4 -6
- data/lib/dm-core/repository.rb +21 -6
- data/lib/dm-core/resource.rb +316 -133
- data/lib/dm-core/resource/state.rb +79 -0
- data/lib/dm-core/resource/state/clean.rb +40 -0
- data/lib/dm-core/resource/state/deleted.rb +30 -0
- data/lib/dm-core/resource/state/dirty.rb +86 -0
- data/lib/dm-core/resource/state/immutable.rb +34 -0
- data/lib/dm-core/resource/state/persisted.rb +29 -0
- data/lib/dm-core/resource/state/transient.rb +70 -0
- data/lib/dm-core/spec/lib/adapter_helpers.rb +52 -0
- data/lib/dm-core/spec/lib/collection_helpers.rb +20 -0
- data/{spec → lib/dm-core/spec}/lib/counter_adapter.rb +5 -1
- data/lib/dm-core/spec/lib/pending_helpers.rb +50 -0
- data/lib/dm-core/spec/lib/spec_helper.rb +68 -0
- data/lib/dm-core/spec/setup.rb +165 -0
- data/lib/dm-core/spec/{adapter_shared_spec.rb → shared/adapter_spec.rb} +21 -7
- data/{spec/public/shared/resource_shared_spec.rb → lib/dm-core/spec/shared/resource_spec.rb} +120 -83
- data/{spec/public/shared/sel_shared_spec.rb → lib/dm-core/spec/shared/sel_spec.rb} +5 -6
- data/lib/dm-core/support/assertions.rb +8 -0
- data/lib/dm-core/support/equalizer.rb +1 -0
- data/lib/dm-core/support/hook.rb +420 -0
- data/lib/dm-core/support/lazy_array.rb +453 -0
- data/lib/dm-core/support/local_object_space.rb +12 -0
- data/lib/dm-core/support/logger.rb +193 -6
- data/lib/dm-core/support/naming_conventions.rb +8 -8
- data/lib/dm-core/support/subject.rb +33 -0
- data/lib/dm-core/type.rb +4 -0
- data/lib/dm-core/types/boolean.rb +2 -0
- data/lib/dm-core/types/decimal.rb +9 -0
- data/lib/dm-core/types/discriminator.rb +2 -0
- data/lib/dm-core/types/object.rb +3 -0
- data/lib/dm-core/types/serial.rb +2 -0
- data/lib/dm-core/types/text.rb +2 -0
- data/lib/dm-core/version.rb +1 -1
- data/spec/public/associations/many_to_many/read_multiple_join_spec.rb +67 -0
- data/spec/public/model/hook_spec.rb +209 -0
- data/spec/public/model/property_spec.rb +35 -0
- data/spec/public/model/relationship_spec.rb +33 -20
- data/spec/public/model_spec.rb +142 -10
- data/spec/public/property/binary_spec.rb +14 -0
- data/spec/public/property/boolean_spec.rb +14 -0
- data/spec/public/property/class_spec.rb +20 -0
- data/spec/public/property/date_spec.rb +14 -0
- data/spec/public/property/date_time_spec.rb +14 -0
- data/spec/public/property/decimal_spec.rb +14 -0
- data/spec/public/{types → property}/discriminator_spec.rb +2 -12
- data/spec/public/property/float_spec.rb +14 -0
- data/spec/public/property/integer_spec.rb +14 -0
- data/spec/public/property/object_spec.rb +9 -17
- data/spec/public/property/serial_spec.rb +14 -0
- data/spec/public/property/string_spec.rb +14 -0
- data/spec/public/property/text_spec.rb +52 -0
- data/spec/public/property/time_spec.rb +14 -0
- data/spec/public/property_spec.rb +28 -87
- data/spec/public/resource_spec.rb +101 -0
- data/spec/public/sel_spec.rb +5 -15
- data/spec/public/shared/collection_shared_spec.rb +16 -30
- data/spec/public/shared/finder_shared_spec.rb +2 -4
- data/spec/public/shared/property_shared_spec.rb +176 -0
- data/spec/semipublic/adapters/abstract_adapter_spec.rb +1 -1
- data/spec/semipublic/adapters/in_memory_adapter_spec.rb +2 -2
- data/spec/semipublic/associations/many_to_many_spec.rb +89 -0
- data/spec/semipublic/associations/many_to_one_spec.rb +24 -1
- data/spec/semipublic/associations/one_to_many_spec.rb +51 -0
- data/spec/semipublic/associations/one_to_one_spec.rb +49 -0
- data/spec/semipublic/associations/relationship_spec.rb +3 -3
- data/spec/semipublic/associations_spec.rb +1 -1
- data/spec/semipublic/property/binary_spec.rb +13 -0
- data/spec/semipublic/property/boolean_spec.rb +65 -0
- data/spec/semipublic/property/class_spec.rb +33 -0
- data/spec/semipublic/property/date_spec.rb +43 -0
- data/spec/semipublic/property/date_time_spec.rb +46 -0
- data/spec/semipublic/property/decimal_spec.rb +82 -0
- data/spec/semipublic/property/discriminator_spec.rb +19 -0
- data/spec/semipublic/property/float_spec.rb +82 -0
- data/spec/semipublic/property/integer_spec.rb +82 -0
- data/spec/semipublic/property/serial_spec.rb +13 -0
- data/spec/semipublic/property/string_spec.rb +13 -0
- data/spec/semipublic/property/text_spec.rb +31 -0
- data/spec/semipublic/property/time_spec.rb +50 -0
- data/spec/semipublic/property_spec.rb +2 -532
- data/spec/semipublic/query/conditions/comparison_spec.rb +171 -169
- data/spec/semipublic/query/conditions/operation_spec.rb +53 -51
- data/spec/semipublic/query/path_spec.rb +17 -17
- data/spec/semipublic/query_spec.rb +47 -78
- data/spec/semipublic/resource/state/clean_spec.rb +88 -0
- data/spec/semipublic/resource/state/deleted_spec.rb +78 -0
- data/spec/semipublic/resource/state/dirty_spec.rb +133 -0
- data/spec/semipublic/resource/state/immutable_spec.rb +99 -0
- data/spec/semipublic/resource/state/transient_spec.rb +128 -0
- data/spec/semipublic/resource/state_spec.rb +226 -0
- data/spec/semipublic/shared/property_shared_spec.rb +143 -0
- data/spec/semipublic/shared/resource_shared_spec.rb +16 -15
- data/spec/semipublic/shared/resource_state_shared_spec.rb +78 -0
- data/spec/semipublic/shared/subject_shared_spec.rb +79 -0
- data/spec/spec_helper.rb +21 -97
- data/spec/support/types/huge_integer.rb +17 -0
- data/spec/unit/array_spec.rb +48 -0
- data/spec/unit/hash_spec.rb +35 -0
- data/spec/unit/hook_spec.rb +1234 -0
- data/spec/unit/lazy_array_spec.rb +1959 -0
- data/spec/unit/module_spec.rb +70 -0
- data/spec/unit/object_spec.rb +37 -0
- data/spec/unit/try_dup_spec.rb +45 -0
- data/tasks/local_gemfile.rake +18 -0
- data/tasks/spec.rake +0 -3
- metadata +197 -71
- data/deps.rip +0 -2
- data/lib/dm-core/adapters/data_objects_adapter.rb +0 -712
- data/lib/dm-core/adapters/mysql_adapter.rb +0 -42
- data/lib/dm-core/adapters/oracle_adapter.rb +0 -229
- data/lib/dm-core/adapters/postgres_adapter.rb +0 -22
- data/lib/dm-core/adapters/sqlite3_adapter.rb +0 -17
- data/lib/dm-core/adapters/sqlserver_adapter.rb +0 -114
- data/lib/dm-core/adapters/yaml_adapter.rb +0 -111
- data/lib/dm-core/core_ext/enumerable.rb +0 -28
- data/lib/dm-core/migrations.rb +0 -1427
- data/lib/dm-core/spec/data_objects_adapter_shared_spec.rb +0 -366
- data/lib/dm-core/transaction.rb +0 -508
- data/lib/dm-core/types/paranoid_boolean.rb +0 -42
- data/lib/dm-core/types/paranoid_datetime.rb +0 -41
- data/spec/lib/adapter_helpers.rb +0 -105
- data/spec/lib/collection_helpers.rb +0 -18
- data/spec/lib/pending_helpers.rb +0 -46
- data/spec/public/migrations_spec.rb +0 -503
- data/spec/public/transaction_spec.rb +0 -153
- data/spec/semipublic/adapters/mysql_adapter_spec.rb +0 -17
- data/spec/semipublic/adapters/oracle_adapter_spec.rb +0 -194
- data/spec/semipublic/adapters/postgres_adapter_spec.rb +0 -17
- data/spec/semipublic/adapters/sqlite3_adapter_spec.rb +0 -17
- data/spec/semipublic/adapters/sqlserver_adapter_spec.rb +0 -17
- data/spec/semipublic/adapters/yaml_adapter_spec.rb +0 -12
@@ -0,0 +1,12 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module LocalObjectSpace
|
3
|
+
def self.extended(klass)
|
4
|
+
(class << klass; self; end).send :attr_accessor, :hook_scopes
|
5
|
+
klass.hook_scopes = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def object_by_id(object_id)
|
9
|
+
self.hook_scopes.detect { |object| object.object_id == object_id }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,13 +1,200 @@
|
|
1
|
+
require "time" # httpdate
|
2
|
+
# ==== Public Extlib Logger API
|
3
|
+
#
|
4
|
+
# To replace an existing logger with a new one:
|
5
|
+
# Extlib::Logger.set_log(log{String, IO},level{Symbol, String})
|
6
|
+
#
|
7
|
+
# Available logging levels are
|
8
|
+
# Extlib::Logger::{ Fatal, Error, Warn, Info, Debug }
|
9
|
+
#
|
10
|
+
# Logging via:
|
11
|
+
# Extlib.logger.fatal(message<String>,&block)
|
12
|
+
# Extlib.logger.error(message<String>,&block)
|
13
|
+
# Extlib.logger.warn(message<String>,&block)
|
14
|
+
# Extlib.logger.info(message<String>,&block)
|
15
|
+
# Extlib.logger.debug(message<String>,&block)
|
16
|
+
#
|
17
|
+
# Logging with autoflush:
|
18
|
+
# Extlib.logger.fatal!(message<String>,&block)
|
19
|
+
# Extlib.logger.error!(message<String>,&block)
|
20
|
+
# Extlib.logger.warn!(message<String>,&block)
|
21
|
+
# Extlib.logger.info!(message<String>,&block)
|
22
|
+
# Extlib.logger.debug!(message<String>,&block)
|
23
|
+
#
|
24
|
+
# Flush the buffer to
|
25
|
+
# Extlib.logger.flush
|
26
|
+
#
|
27
|
+
# Remove the current log object
|
28
|
+
# Extlib.logger.close
|
29
|
+
#
|
30
|
+
# ==== Private Extlib Logger API
|
31
|
+
#
|
32
|
+
# To initialize the logger you create a new object, proxies to set_log.
|
33
|
+
# Extlib::Logger.new(log{String, IO},level{Symbol, String})
|
1
34
|
module DataMapper
|
2
|
-
|
35
|
+
|
36
|
+
class << self
|
3
37
|
attr_accessor :logger
|
4
38
|
end
|
5
39
|
|
6
|
-
class Logger
|
7
|
-
|
8
|
-
|
40
|
+
class Logger
|
41
|
+
|
42
|
+
attr_accessor :level
|
43
|
+
attr_accessor :delimiter
|
44
|
+
attr_accessor :auto_flush
|
45
|
+
attr_reader :buffer
|
46
|
+
attr_reader :log
|
47
|
+
attr_reader :init_args
|
48
|
+
|
49
|
+
# ==== Notes
|
50
|
+
# Ruby (standard) logger levels:
|
51
|
+
# :fatal:: An unhandleable error that results in a program crash
|
52
|
+
# :error:: A handleable error condition
|
53
|
+
# :warn:: A warning
|
54
|
+
# :info:: generic (useful) information about system operation
|
55
|
+
# :debug:: low-level information for developers
|
56
|
+
Levels =
|
57
|
+
{
|
58
|
+
:fatal => 7,
|
59
|
+
:error => 6,
|
60
|
+
:warn => 4,
|
61
|
+
:info => 3,
|
62
|
+
:debug => 0
|
63
|
+
}
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
# Readies a log for writing.
|
68
|
+
#
|
69
|
+
# ==== Parameters
|
70
|
+
# log<IO, String>:: Either an IO object or a name of a logfile.
|
71
|
+
def initialize_log(log)
|
72
|
+
close if @log # be sure that we don't leave open files laying around.
|
73
|
+
|
74
|
+
if log.respond_to?(:write)
|
75
|
+
@log = log
|
76
|
+
elsif File.exist?(log)
|
77
|
+
@log = open(log, (File::WRONLY | File::APPEND))
|
78
|
+
@log.sync = true
|
79
|
+
else
|
80
|
+
FileUtils.mkdir_p(File.dirname(log)) unless File.directory?(File.dirname(log))
|
81
|
+
@log = open(log, (File::WRONLY | File::APPEND | File::CREAT))
|
82
|
+
@log.sync = true
|
83
|
+
@log.write("#{Time.now.httpdate} #{delimiter} info #{delimiter} Logfile created\n")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
public
|
88
|
+
|
89
|
+
# To initialize the logger you create a new object, proxies to set_log.
|
90
|
+
#
|
91
|
+
# ==== Parameters
|
92
|
+
# *args:: Arguments to create the log from. See set_logs for specifics.
|
93
|
+
def initialize(*args)
|
94
|
+
@init_args = args
|
95
|
+
set_log(*args)
|
9
96
|
self.auto_flush = true
|
10
97
|
DataMapper.logger = self
|
11
98
|
end
|
12
|
-
|
13
|
-
|
99
|
+
|
100
|
+
# Replaces an existing logger with a new one.
|
101
|
+
#
|
102
|
+
# ==== Parameters
|
103
|
+
# log<IO, String>:: Either an IO object or a name of a logfile.
|
104
|
+
# log_level<~to_sym>::
|
105
|
+
# The log level from, e.g. :fatal or :info. Defaults to :error in the
|
106
|
+
# production environment and :debug otherwise.
|
107
|
+
# delimiter<String>::
|
108
|
+
# Delimiter to use between message sections. Defaults to " ~ ".
|
109
|
+
# auto_flush<Boolean>::
|
110
|
+
# Whether the log should automatically flush after new messages are
|
111
|
+
# added. Defaults to false.
|
112
|
+
def set_log(log, log_level = nil, delimiter = " ~ ", auto_flush = false)
|
113
|
+
if log_level && Levels[log_level.to_sym]
|
114
|
+
@level = Levels[log_level.to_sym]
|
115
|
+
else
|
116
|
+
@level = Levels[:debug]
|
117
|
+
end
|
118
|
+
@buffer = []
|
119
|
+
@delimiter = delimiter
|
120
|
+
@auto_flush = auto_flush
|
121
|
+
|
122
|
+
initialize_log(log)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Flush the entire buffer to the log object.
|
126
|
+
def flush
|
127
|
+
return unless @buffer.size > 0
|
128
|
+
@log.write(@buffer.slice!(0..-1).join)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Close and remove the current log object.
|
132
|
+
def close
|
133
|
+
flush
|
134
|
+
@log.close if @log.respond_to?(:close) && !@log.tty?
|
135
|
+
@log = nil
|
136
|
+
end
|
137
|
+
|
138
|
+
# Appends a message to the log. The methods yield to an optional block and
|
139
|
+
# the output of this block will be appended to the message.
|
140
|
+
#
|
141
|
+
# ==== Parameters
|
142
|
+
# string<String>:: The message to be logged. Defaults to nil.
|
143
|
+
#
|
144
|
+
# ==== Returns
|
145
|
+
# String:: The resulting message added to the log file.
|
146
|
+
def <<(string = nil)
|
147
|
+
message = ""
|
148
|
+
message << delimiter
|
149
|
+
message << string if string
|
150
|
+
message << "\n" unless message[-1] == ?\n
|
151
|
+
@buffer << message
|
152
|
+
flush if @auto_flush
|
153
|
+
|
154
|
+
message
|
155
|
+
end
|
156
|
+
alias :push :<<
|
157
|
+
|
158
|
+
# Generate the logging methods for Extlib.logger for each log level.
|
159
|
+
Levels.each_pair do |name, number|
|
160
|
+
class_eval <<-LEVELMETHODS, __FILE__, __LINE__
|
161
|
+
|
162
|
+
# Appends a message to the log if the log level is at least as high as
|
163
|
+
# the log level of the logger.
|
164
|
+
#
|
165
|
+
# ==== Parameters
|
166
|
+
# string<String>:: The message to be logged. Defaults to nil.
|
167
|
+
#
|
168
|
+
# ==== Returns
|
169
|
+
# self:: The logger object for chaining.
|
170
|
+
def #{name}(message = nil)
|
171
|
+
self << message if #{number} >= level
|
172
|
+
self
|
173
|
+
end
|
174
|
+
|
175
|
+
# Appends a message to the log if the log level is at least as high as
|
176
|
+
# the log level of the logger. The bang! version of the method also auto
|
177
|
+
# flushes the log buffer to disk.
|
178
|
+
#
|
179
|
+
# ==== Parameters
|
180
|
+
# string<String>:: The message to be logged. Defaults to nil.
|
181
|
+
#
|
182
|
+
# ==== Returns
|
183
|
+
# self:: The logger object for chaining.
|
184
|
+
def #{name}!(message = nil)
|
185
|
+
self << message if #{number} >= level
|
186
|
+
flush if #{number} >= level
|
187
|
+
self
|
188
|
+
end
|
189
|
+
|
190
|
+
# ==== Returns
|
191
|
+
# Boolean:: True if this level will be logged by this logger.
|
192
|
+
def #{name}?
|
193
|
+
#{number} >= level
|
194
|
+
end
|
195
|
+
LEVELMETHODS
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
@@ -28,25 +28,25 @@ module DataMapper
|
|
28
28
|
|
29
29
|
module UnderscoredAndPluralized
|
30
30
|
def self.call(name)
|
31
|
-
|
31
|
+
ActiveSupport::Inflector.pluralize(ActiveSupport::Inflector.underscore(name)).gsub('/', '_')
|
32
32
|
end
|
33
33
|
end # module UnderscoredAndPluralized
|
34
34
|
|
35
35
|
module UnderscoredAndPluralizedWithoutModule
|
36
36
|
def self.call(name)
|
37
|
-
|
37
|
+
ActiveSupport::Inflector.pluralize(ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(name)))
|
38
38
|
end
|
39
39
|
end # module UnderscoredAndPluralizedWithoutModule
|
40
40
|
|
41
41
|
module Underscored
|
42
42
|
def self.call(name)
|
43
|
-
|
43
|
+
ActiveSupport::Inflector.underscore(name)
|
44
44
|
end
|
45
45
|
end # module Underscored
|
46
46
|
|
47
47
|
module Yaml
|
48
48
|
def self.call(name)
|
49
|
-
"#{
|
49
|
+
"#{ActiveSupport::Inflector.pluralize(ActiveSupport::Inflector.underscore(name))}.yaml"
|
50
50
|
end
|
51
51
|
end # module Yaml
|
52
52
|
|
@@ -56,25 +56,25 @@ module DataMapper
|
|
56
56
|
|
57
57
|
module UnderscoredAndPluralized
|
58
58
|
def self.call(property)
|
59
|
-
|
59
|
+
ActiveSupport::Inflector.pluralize(ActiveSupport::Inflector.underscore(property.name.to_s)).gsub('/', '_')
|
60
60
|
end
|
61
61
|
end # module UnderscoredAndPluralized
|
62
62
|
|
63
63
|
module UnderscoredAndPluralizedWithoutModule
|
64
64
|
def self.call(property)
|
65
|
-
|
65
|
+
ActiveSupport::Inflector.pluralize(ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(property.name.to_s)))
|
66
66
|
end
|
67
67
|
end # module UnderscoredAndPluralizedWithoutModule
|
68
68
|
|
69
69
|
module Underscored
|
70
70
|
def self.call(property)
|
71
|
-
|
71
|
+
ActiveSupport::Inflector.underscore(property.name.to_s)
|
72
72
|
end
|
73
73
|
end # module Underscored
|
74
74
|
|
75
75
|
module Yaml
|
76
76
|
def self.call(property)
|
77
|
-
"#{
|
77
|
+
"#{ActiveSupport::Inflector.pluralize(ActiveSupport::Inflector.underscore(property.name.to_s))}.yaml"
|
78
78
|
end
|
79
79
|
end # module Yaml
|
80
80
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Subject
|
3
|
+
# Returns a default value of the subject for given resource
|
4
|
+
#
|
5
|
+
# When default value is a callable object, it is called with resource
|
6
|
+
# and subject passed as arguments.
|
7
|
+
#
|
8
|
+
# @param [Resource] resource
|
9
|
+
# the model instance for which the default is to be set
|
10
|
+
#
|
11
|
+
# @return [Object]
|
12
|
+
# the default value of this subject for +resource+
|
13
|
+
#
|
14
|
+
# @api semipublic
|
15
|
+
def default_for(resource)
|
16
|
+
if @default.respond_to?(:call)
|
17
|
+
@default.call(resource, self)
|
18
|
+
else
|
19
|
+
@default.try_dup
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns true if the subject has a default value
|
24
|
+
#
|
25
|
+
# @return [Boolean]
|
26
|
+
# true if the subject has a default value
|
27
|
+
#
|
28
|
+
# @api semipublic
|
29
|
+
def default?
|
30
|
+
@options.key?(:default)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/dm-core/type.rb
CHANGED
@@ -83,6 +83,10 @@ module DataMapper
|
|
83
83
|
# JSON = Json
|
84
84
|
# end # module Types
|
85
85
|
# end # module DataMapper
|
86
|
+
|
87
|
+
# TODO: this is only for the backward compatibility in case someone's subclassing from one of the deprecated types
|
88
|
+
module Types; end
|
89
|
+
|
86
90
|
class Type
|
87
91
|
# Until cooperation of Property and Type does not change, each must
|
88
92
|
# have a separate list of options, because plugins (ex.: dm-validations)
|
data/lib/dm-core/types/object.rb
CHANGED
data/lib/dm-core/types/serial.rb
CHANGED
data/lib/dm-core/types/text.rb
CHANGED
data/lib/dm-core/version.rb
CHANGED
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe 'Many to Many Associations read across multiple join associations' do
|
4
|
+
before :all do
|
5
|
+
class ::User
|
6
|
+
include DataMapper::Resource
|
7
|
+
|
8
|
+
property :id, Serial
|
9
|
+
|
10
|
+
has n, :sales
|
11
|
+
has n, :sale_items, :through => :sales
|
12
|
+
has n, :items, :through => :sale_items
|
13
|
+
end
|
14
|
+
|
15
|
+
class ::Sale
|
16
|
+
include DataMapper::Resource
|
17
|
+
|
18
|
+
property :id, Serial
|
19
|
+
|
20
|
+
belongs_to :user
|
21
|
+
has n, :sale_items
|
22
|
+
has n, :items, :through => :sale_items
|
23
|
+
end
|
24
|
+
|
25
|
+
class ::SaleItem
|
26
|
+
include DataMapper::Resource
|
27
|
+
|
28
|
+
property :id, Serial
|
29
|
+
|
30
|
+
belongs_to :sale
|
31
|
+
belongs_to :item
|
32
|
+
end
|
33
|
+
|
34
|
+
class ::Item
|
35
|
+
include DataMapper::Resource
|
36
|
+
|
37
|
+
property :id, Serial
|
38
|
+
|
39
|
+
has n, :sale_items
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
supported_by :all do
|
44
|
+
before :all do
|
45
|
+
@user = User.create
|
46
|
+
@sale = @user.sales.create
|
47
|
+
|
48
|
+
5.times { @sale.items.create }
|
49
|
+
end
|
50
|
+
|
51
|
+
before :all do
|
52
|
+
@no_join = defined?(DataMapper::Adapters::InMemoryAdapter) && @adapter.kind_of?(DataMapper::Adapters::InMemoryAdapter) ||
|
53
|
+
defined?(DataMapper::Adapters::YamlAdapter) && @adapter.kind_of?(DataMapper::Adapters::YamlAdapter)
|
54
|
+
|
55
|
+
@skip = @no_join
|
56
|
+
end
|
57
|
+
|
58
|
+
before do
|
59
|
+
pending if @skip
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should return all the created entries' do
|
63
|
+
@user.items.to_a.should == Item.all.to_a
|
64
|
+
@sale.items.to_a.should == Item.all.to_a
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|