datamapper-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.
- data/.autotest +17 -14
- data/.gitignore +3 -1
- data/FAQ +6 -5
- data/History.txt +5 -39
- data/Manifest.txt +67 -76
- data/QUICKLINKS +1 -1
- data/README.txt +21 -15
- data/Rakefile +16 -15
- data/SPECS +2 -29
- data/TODO +1 -1
- data/dm-core.gemspec +11 -15
- data/lib/dm-core/adapters/abstract_adapter.rb +182 -185
- data/lib/dm-core/adapters/data_objects_adapter.rb +482 -534
- data/lib/dm-core/adapters/in_memory_adapter.rb +90 -69
- data/lib/dm-core/adapters/mysql_adapter.rb +22 -115
- data/lib/dm-core/adapters/oracle_adapter.rb +249 -0
- data/lib/dm-core/adapters/postgres_adapter.rb +7 -173
- data/lib/dm-core/adapters/sqlite3_adapter.rb +4 -97
- data/lib/dm-core/adapters/yaml_adapter.rb +116 -0
- data/lib/dm-core/adapters.rb +135 -16
- data/lib/dm-core/associations/many_to_many.rb +372 -90
- data/lib/dm-core/associations/many_to_one.rb +220 -73
- data/lib/dm-core/associations/one_to_many.rb +319 -255
- data/lib/dm-core/associations/one_to_one.rb +66 -53
- data/lib/dm-core/associations/relationship.rb +560 -158
- data/lib/dm-core/collection.rb +1104 -381
- data/lib/dm-core/core_ext/kernel.rb +12 -0
- data/lib/dm-core/core_ext/symbol.rb +10 -0
- data/lib/dm-core/identity_map.rb +4 -34
- data/lib/dm-core/migrations.rb +1283 -0
- data/lib/dm-core/model/descendant_set.rb +81 -0
- data/lib/dm-core/model/hook.rb +45 -0
- data/lib/dm-core/model/is.rb +32 -0
- data/lib/dm-core/model/property.rb +248 -0
- data/lib/dm-core/model/relationship.rb +335 -0
- data/lib/dm-core/model/scope.rb +90 -0
- data/lib/dm-core/model.rb +570 -369
- data/lib/dm-core/property.rb +753 -280
- data/lib/dm-core/property_set.rb +141 -98
- data/lib/dm-core/query/conditions/comparison.rb +814 -0
- data/lib/dm-core/query/conditions/operation.rb +247 -0
- data/lib/dm-core/query/direction.rb +43 -0
- data/lib/dm-core/query/operator.rb +42 -0
- data/lib/dm-core/query/path.rb +102 -0
- data/lib/dm-core/query/sort.rb +45 -0
- data/lib/dm-core/query.rb +974 -492
- data/lib/dm-core/repository.rb +147 -107
- data/lib/dm-core/resource.rb +644 -429
- data/lib/dm-core/spec/adapter_shared_spec.rb +294 -0
- data/lib/dm-core/spec/data_objects_adapter_shared_spec.rb +106 -0
- data/lib/dm-core/support/chainable.rb +20 -0
- data/lib/dm-core/support/deprecate.rb +12 -0
- data/lib/dm-core/support/equalizer.rb +23 -0
- data/lib/dm-core/support/logger.rb +13 -0
- data/lib/dm-core/{naming_conventions.rb → support/naming_conventions.rb} +6 -6
- data/lib/dm-core/transaction.rb +333 -92
- data/lib/dm-core/type.rb +98 -60
- data/lib/dm-core/types/boolean.rb +1 -1
- data/lib/dm-core/types/discriminator.rb +34 -20
- data/lib/dm-core/types/object.rb +7 -4
- data/lib/dm-core/types/paranoid_boolean.rb +11 -9
- data/lib/dm-core/types/paranoid_datetime.rb +11 -9
- data/lib/dm-core/types/serial.rb +3 -3
- data/lib/dm-core/types/text.rb +3 -4
- data/lib/dm-core/version.rb +1 -1
- data/lib/dm-core.rb +106 -110
- data/script/performance.rb +102 -109
- data/script/profile.rb +169 -38
- data/spec/lib/adapter_helpers.rb +105 -0
- data/spec/lib/collection_helpers.rb +18 -0
- data/spec/lib/counter_adapter.rb +34 -0
- data/spec/lib/pending_helpers.rb +27 -0
- data/spec/lib/rspec_immediate_feedback_formatter.rb +53 -0
- data/spec/public/associations/many_to_many_spec.rb +193 -0
- data/spec/public/associations/many_to_one_spec.rb +73 -0
- data/spec/public/associations/one_to_many_spec.rb +77 -0
- data/spec/public/associations/one_to_one_spec.rb +156 -0
- data/spec/public/collection_spec.rb +65 -0
- data/spec/public/model/relationship_spec.rb +924 -0
- data/spec/public/model_spec.rb +159 -0
- data/spec/public/property_spec.rb +829 -0
- data/spec/public/resource_spec.rb +71 -0
- data/spec/public/sel_spec.rb +44 -0
- data/spec/public/setup_spec.rb +145 -0
- data/spec/public/shared/association_collection_shared_spec.rb +317 -0
- data/spec/public/shared/collection_shared_spec.rb +1723 -0
- data/spec/public/shared/finder_shared_spec.rb +1619 -0
- data/spec/public/shared/resource_shared_spec.rb +924 -0
- data/spec/public/shared/sel_shared_spec.rb +112 -0
- data/spec/public/transaction_spec.rb +129 -0
- data/spec/public/types/discriminator_spec.rb +130 -0
- data/spec/semipublic/adapters/abstract_adapter_spec.rb +30 -0
- data/spec/semipublic/adapters/in_memory_adapter_spec.rb +12 -0
- data/spec/semipublic/adapters/mysql_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/oracle_adapter_spec.rb +194 -0
- data/spec/semipublic/adapters/postgres_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/sqlite3_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/yaml_adapter_spec.rb +12 -0
- data/spec/semipublic/associations/many_to_one_spec.rb +53 -0
- data/spec/semipublic/associations/relationship_spec.rb +194 -0
- data/spec/semipublic/associations_spec.rb +177 -0
- data/spec/semipublic/collection_spec.rb +142 -0
- data/spec/semipublic/property_spec.rb +61 -0
- data/spec/semipublic/query/conditions_spec.rb +528 -0
- data/spec/semipublic/query/path_spec.rb +443 -0
- data/spec/semipublic/query_spec.rb +2626 -0
- data/spec/semipublic/resource_spec.rb +47 -0
- data/spec/semipublic/shared/resource_shared_spec.rb +126 -0
- data/spec/spec.opts +3 -1
- data/spec/spec_helper.rb +80 -57
- data/tasks/ci.rb +19 -31
- data/tasks/dm.rb +43 -48
- data/tasks/doc.rb +8 -11
- data/tasks/gemspec.rb +5 -5
- data/tasks/hoe.rb +15 -16
- data/tasks/install.rb +8 -10
- metadata +72 -93
- data/lib/dm-core/associations/relationship_chain.rb +0 -81
- data/lib/dm-core/associations.rb +0 -207
- data/lib/dm-core/auto_migrations.rb +0 -105
- data/lib/dm-core/dependency_queue.rb +0 -32
- data/lib/dm-core/hook.rb +0 -11
- data/lib/dm-core/is.rb +0 -16
- data/lib/dm-core/logger.rb +0 -232
- data/lib/dm-core/migrations/destructive_migrations.rb +0 -17
- data/lib/dm-core/migrator.rb +0 -29
- data/lib/dm-core/scope.rb +0 -58
- data/lib/dm-core/support/array.rb +0 -13
- data/lib/dm-core/support/assertions.rb +0 -8
- data/lib/dm-core/support/errors.rb +0 -23
- data/lib/dm-core/support/kernel.rb +0 -11
- data/lib/dm-core/support/symbol.rb +0 -41
- data/lib/dm-core/support.rb +0 -7
- data/lib/dm-core/type_map.rb +0 -80
- data/lib/dm-core/types.rb +0 -19
- data/script/all +0 -4
- data/spec/integration/association_spec.rb +0 -1382
- data/spec/integration/association_through_spec.rb +0 -203
- data/spec/integration/associations/many_to_many_spec.rb +0 -449
- data/spec/integration/associations/many_to_one_spec.rb +0 -163
- data/spec/integration/associations/one_to_many_spec.rb +0 -188
- data/spec/integration/auto_migrations_spec.rb +0 -413
- data/spec/integration/collection_spec.rb +0 -1073
- data/spec/integration/data_objects_adapter_spec.rb +0 -32
- data/spec/integration/dependency_queue_spec.rb +0 -46
- data/spec/integration/model_spec.rb +0 -197
- data/spec/integration/mysql_adapter_spec.rb +0 -85
- data/spec/integration/postgres_adapter_spec.rb +0 -731
- data/spec/integration/property_spec.rb +0 -253
- data/spec/integration/query_spec.rb +0 -514
- data/spec/integration/repository_spec.rb +0 -61
- data/spec/integration/resource_spec.rb +0 -513
- data/spec/integration/sqlite3_adapter_spec.rb +0 -352
- data/spec/integration/sti_spec.rb +0 -273
- data/spec/integration/strategic_eager_loading_spec.rb +0 -156
- data/spec/integration/transaction_spec.rb +0 -75
- data/spec/integration/type_spec.rb +0 -275
- data/spec/lib/logging_helper.rb +0 -18
- data/spec/lib/mock_adapter.rb +0 -27
- data/spec/lib/model_loader.rb +0 -100
- data/spec/lib/publicize_methods.rb +0 -28
- data/spec/models/content.rb +0 -16
- data/spec/models/vehicles.rb +0 -34
- data/spec/models/zoo.rb +0 -48
- data/spec/unit/adapters/abstract_adapter_spec.rb +0 -133
- data/spec/unit/adapters/adapter_shared_spec.rb +0 -15
- data/spec/unit/adapters/data_objects_adapter_spec.rb +0 -632
- data/spec/unit/adapters/in_memory_adapter_spec.rb +0 -98
- data/spec/unit/adapters/postgres_adapter_spec.rb +0 -133
- data/spec/unit/associations/many_to_many_spec.rb +0 -32
- data/spec/unit/associations/many_to_one_spec.rb +0 -159
- data/spec/unit/associations/one_to_many_spec.rb +0 -393
- data/spec/unit/associations/one_to_one_spec.rb +0 -7
- data/spec/unit/associations/relationship_spec.rb +0 -71
- data/spec/unit/associations_spec.rb +0 -242
- data/spec/unit/auto_migrations_spec.rb +0 -111
- data/spec/unit/collection_spec.rb +0 -182
- data/spec/unit/data_mapper_spec.rb +0 -35
- data/spec/unit/identity_map_spec.rb +0 -126
- data/spec/unit/is_spec.rb +0 -80
- data/spec/unit/migrator_spec.rb +0 -33
- data/spec/unit/model_spec.rb +0 -321
- data/spec/unit/naming_conventions_spec.rb +0 -36
- data/spec/unit/property_set_spec.rb +0 -90
- data/spec/unit/property_spec.rb +0 -753
- data/spec/unit/query_spec.rb +0 -571
- data/spec/unit/repository_spec.rb +0 -93
- data/spec/unit/resource_spec.rb +0 -649
- data/spec/unit/scope_spec.rb +0 -142
- data/spec/unit/transaction_spec.rb +0 -493
- data/spec/unit/type_map_spec.rb +0 -114
- data/spec/unit/type_spec.rb +0 -119
data/lib/dm-core/is.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module DataMapper
|
2
|
-
module Is
|
3
|
-
|
4
|
-
def is(plugin, *pars, &block)
|
5
|
-
generator_method = "is_#{plugin}".to_sym
|
6
|
-
|
7
|
-
if self.respond_to?(generator_method)
|
8
|
-
self.send(generator_method, *pars, &block)
|
9
|
-
else
|
10
|
-
raise PluginNotFoundError, "could not find plugin named #{plugin}"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
Model.send(:include, self)
|
15
|
-
end # module Is
|
16
|
-
end # module DataMapper
|
data/lib/dm-core/logger.rb
DELETED
@@ -1,232 +0,0 @@
|
|
1
|
-
require "time" # httpdate
|
2
|
-
# ==== Public DataMapper Logger API
|
3
|
-
#
|
4
|
-
# Logger taken from Merb :)
|
5
|
-
#
|
6
|
-
# To replace an existing logger with a new one:
|
7
|
-
# DataMapper.logger.set_log(log{String, IO},level{Symbol, String})
|
8
|
-
#
|
9
|
-
# Available logging levels are:
|
10
|
-
# :off, :fatal, :error, :warn, :info, :debug
|
11
|
-
#
|
12
|
-
# Logging via:
|
13
|
-
# DataMapper.logger.fatal(message<String>)
|
14
|
-
# DataMapper.logger.error(message<String>)
|
15
|
-
# DataMapper.logger.warn(message<String>)
|
16
|
-
# DataMapper.logger.info(message<String>)
|
17
|
-
# DataMapper.logger.debug(message<String>)
|
18
|
-
#
|
19
|
-
# Flush the buffer to
|
20
|
-
# DataMapper.logger.flush
|
21
|
-
#
|
22
|
-
# Remove the current log object
|
23
|
-
# DataMapper.logger.close
|
24
|
-
#
|
25
|
-
# ==== Private DataMapper Logger API
|
26
|
-
#
|
27
|
-
# To initialize the logger you create a new object, proxies to set_log.
|
28
|
-
# DataMapper::Logger.new(log{String, IO}, level{Symbol, String})
|
29
|
-
#
|
30
|
-
# Logger will not create the file until something is actually logged
|
31
|
-
# This avoids file creation on DataMapper init when it creates the
|
32
|
-
# default logger.
|
33
|
-
module DataMapper
|
34
|
-
|
35
|
-
class << self #:nodoc:
|
36
|
-
attr_accessor :logger
|
37
|
-
end
|
38
|
-
|
39
|
-
class Logger
|
40
|
-
|
41
|
-
attr_accessor :aio
|
42
|
-
attr_accessor :delimiter
|
43
|
-
attr_reader :level
|
44
|
-
attr_reader :buffer
|
45
|
-
attr_reader :log
|
46
|
-
|
47
|
-
# @note
|
48
|
-
# Ruby (standard) logger levels:
|
49
|
-
# off: absolutely nothing
|
50
|
-
# fatal: an unhandleable error that results in a program crash
|
51
|
-
# error: a handleable error condition
|
52
|
-
# warn: a warning
|
53
|
-
# info: generic (useful) information about system operation
|
54
|
-
# debug: low-level information for developers
|
55
|
-
#
|
56
|
-
# DataMapper::Logger::LEVELS[:off, :fatal, :error, :warn, :info, :debug]
|
57
|
-
LEVELS =
|
58
|
-
{
|
59
|
-
:off => 99999,
|
60
|
-
:fatal => 7,
|
61
|
-
:error => 6,
|
62
|
-
:warn => 4,
|
63
|
-
:info => 3,
|
64
|
-
:debug => 0
|
65
|
-
}
|
66
|
-
|
67
|
-
def level=(new_level)
|
68
|
-
@level = LEVELS[new_level.to_sym]
|
69
|
-
reset_methods(:close)
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
# The idea here is that instead of performing an 'if' conditional check on
|
75
|
-
# each logging we do it once when the log object is setup
|
76
|
-
def set_write_method
|
77
|
-
@log.instance_eval do
|
78
|
-
|
79
|
-
# Determine if asynchronous IO can be used
|
80
|
-
def aio?
|
81
|
-
@aio = !RUBY_PLATFORM.match(/java|mswin/) &&
|
82
|
-
!(@log == STDOUT) &&
|
83
|
-
@log.respond_to?(:write_nonblock)
|
84
|
-
end
|
85
|
-
|
86
|
-
# Define the write method based on if aio an be used
|
87
|
-
undef write_method if defined? write_method
|
88
|
-
if aio?
|
89
|
-
alias :write_method :write_nonblock
|
90
|
-
else
|
91
|
-
alias :write_method :write
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def initialize_log(log)
|
97
|
-
close if @log # be sure that we don't leave open files laying around.
|
98
|
-
@log = log || "log/dm.log"
|
99
|
-
end
|
100
|
-
|
101
|
-
def reset_methods(o_or_c)
|
102
|
-
if o_or_c == :open
|
103
|
-
alias internal_push push_opened
|
104
|
-
elsif o_or_c == :close
|
105
|
-
alias internal_push push_closed
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def push_opened(string)
|
110
|
-
message = Time.now.httpdate
|
111
|
-
message << delimiter
|
112
|
-
message << string
|
113
|
-
message << "\n" unless message[-1] == ?\n
|
114
|
-
@buffer << message
|
115
|
-
flush # Force a flush for now until we figure out where we want to use the buffering.
|
116
|
-
end
|
117
|
-
|
118
|
-
def push_closed(string)
|
119
|
-
unless @log.respond_to?(:write)
|
120
|
-
log = Pathname(@log)
|
121
|
-
log.dirname.mkpath
|
122
|
-
@log = log.open('a')
|
123
|
-
@log.sync = true
|
124
|
-
end
|
125
|
-
set_write_method
|
126
|
-
reset_methods(:open)
|
127
|
-
push(string)
|
128
|
-
end
|
129
|
-
|
130
|
-
alias internal_push push_closed
|
131
|
-
|
132
|
-
def prep_msg(message, level)
|
133
|
-
level << delimiter << message
|
134
|
-
end
|
135
|
-
|
136
|
-
public
|
137
|
-
|
138
|
-
# To initialize the logger you create a new object, proxies to set_log.
|
139
|
-
# DataMapper::Logger.new(log{String, IO},level{Symbol, String})
|
140
|
-
#
|
141
|
-
# @param log<IO,String> either an IO object or a name of a logfile.
|
142
|
-
# @param log_level<String> the message string to be logged
|
143
|
-
# @param delimiter<String> delimiter to use between message sections
|
144
|
-
# @param log_creation<Boolean> log that the file is being created
|
145
|
-
def initialize(*args)
|
146
|
-
set_log(*args)
|
147
|
-
end
|
148
|
-
|
149
|
-
# To replace an existing logger with a new one:
|
150
|
-
# DataMapper.logger.set_log(log{String, IO},level{Symbol, String})
|
151
|
-
#
|
152
|
-
# @param log<IO,String> either an IO object or a name of a logfile.
|
153
|
-
# @param log_level<Symbol> a symbol representing the log level from
|
154
|
-
# {:off, :fatal, :error, :warn, :info, :debug}
|
155
|
-
# @param delimiter<String> delimiter to use between message sections
|
156
|
-
# @param log_creation<Boolean> log that the file is being created
|
157
|
-
def set_log(log, log_level = :off, delimiter = " ~ ", log_creation = false)
|
158
|
-
delimiter ||= " ~ "
|
159
|
-
|
160
|
-
if log_level && LEVELS[log_level.to_sym]
|
161
|
-
self.level = log_level.to_sym
|
162
|
-
else
|
163
|
-
self.level = :debug
|
164
|
-
end
|
165
|
-
|
166
|
-
@buffer = []
|
167
|
-
@delimiter = delimiter
|
168
|
-
|
169
|
-
initialize_log(log)
|
170
|
-
|
171
|
-
DataMapper.logger = self
|
172
|
-
|
173
|
-
self.info("Logfile created") if log_creation
|
174
|
-
end
|
175
|
-
|
176
|
-
# Flush the entire buffer to the log object.
|
177
|
-
# DataMapper.logger.flush
|
178
|
-
#
|
179
|
-
def flush
|
180
|
-
return unless @buffer.size > 0
|
181
|
-
@log.write_method(@buffer.slice!(0..-1).join)
|
182
|
-
end
|
183
|
-
|
184
|
-
# Close and remove the current log object.
|
185
|
-
# DataMapper.logger.close
|
186
|
-
#
|
187
|
-
def close
|
188
|
-
flush
|
189
|
-
@log.close if @log.respond_to?(:close)
|
190
|
-
@log = nil
|
191
|
-
end
|
192
|
-
|
193
|
-
# Appends a string and log level to logger's buffer.
|
194
|
-
|
195
|
-
# @note
|
196
|
-
# Note that the string is discarded if the string's log level less than the
|
197
|
-
# logger's log level.
|
198
|
-
# @note
|
199
|
-
# Note that if the logger is aio capable then the logger will use
|
200
|
-
# non-blocking asynchronous writes.
|
201
|
-
#
|
202
|
-
# @param level<Fixnum> the logging level as an integer
|
203
|
-
# @param string<String> the message string to be logged
|
204
|
-
def push(string)
|
205
|
-
internal_push(string)
|
206
|
-
end
|
207
|
-
alias << push
|
208
|
-
|
209
|
-
# Generate the following logging methods for DataMapper.logger as described
|
210
|
-
# in the API:
|
211
|
-
# :fatal, :error, :warn, :info, :debug
|
212
|
-
# :off only gets a off? method
|
213
|
-
LEVELS.each_pair do |name, number|
|
214
|
-
unless name.to_s == 'off'
|
215
|
-
class_eval <<-EOS, __FILE__, __LINE__
|
216
|
-
# DOC
|
217
|
-
def #{name}(message)
|
218
|
-
self.<<( prep_msg(message, "#{name}") ) if #{name}?
|
219
|
-
end
|
220
|
-
EOS
|
221
|
-
end
|
222
|
-
|
223
|
-
class_eval <<-EOS, __FILE__, __LINE__
|
224
|
-
# DOC
|
225
|
-
def #{name}?
|
226
|
-
#{number} >= level
|
227
|
-
end
|
228
|
-
EOS
|
229
|
-
end
|
230
|
-
|
231
|
-
end # class Logger
|
232
|
-
end # module DataMapper
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# TODO: move to dm-more/dm-migrations
|
2
|
-
|
3
|
-
module DataMapper
|
4
|
-
module DestructiveMigrations
|
5
|
-
def self.included(model)
|
6
|
-
DestructiveMigrator.models << model
|
7
|
-
end
|
8
|
-
end # module DestructiveMigrations
|
9
|
-
|
10
|
-
class DestructiveMigrator < Migrator
|
11
|
-
def self.migrate(repository_name)
|
12
|
-
models.each do |model|
|
13
|
-
model.auto_migrate!
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end # class DestructiveMigrator
|
17
|
-
end # module DataMapper
|
data/lib/dm-core/migrator.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# TODO: move to dm-more/dm-migrations
|
2
|
-
|
3
|
-
module DataMapper
|
4
|
-
class Migrator
|
5
|
-
def self.subclasses
|
6
|
-
@@subclasses ||= []
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.subclasses=(obj)
|
10
|
-
@@subclasses = obj
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.inherited(klass)
|
14
|
-
subclasses << klass
|
15
|
-
|
16
|
-
class << klass
|
17
|
-
def models
|
18
|
-
@models ||= []
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.migrate(repository_name)
|
24
|
-
subclasses.collect do |migrator|
|
25
|
-
migrator.migrate(repository_name)
|
26
|
-
end.flatten
|
27
|
-
end
|
28
|
-
end # class Migrator
|
29
|
-
end # module DataMapper
|
data/lib/dm-core/scope.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
module DataMapper
|
2
|
-
module Scope
|
3
|
-
Model.append_extensions self
|
4
|
-
|
5
|
-
# @api private
|
6
|
-
def default_scope(repository_name = nil)
|
7
|
-
repository_name = self.default_repository_name if repository_name == :default || repository_name.nil?
|
8
|
-
@default_scope ||= {}
|
9
|
-
@default_scope[repository_name] ||= {}
|
10
|
-
end
|
11
|
-
|
12
|
-
# @api private
|
13
|
-
def query
|
14
|
-
scope_stack.last
|
15
|
-
end
|
16
|
-
|
17
|
-
protected
|
18
|
-
|
19
|
-
# @api semipublic
|
20
|
-
def with_scope(query)
|
21
|
-
# merge the current scope with the passed in query
|
22
|
-
with_exclusive_scope(self.query ? self.query.merge(query) : query) {|*block_args| yield(*block_args) }
|
23
|
-
end
|
24
|
-
|
25
|
-
# @api semipublic
|
26
|
-
def with_exclusive_scope(query)
|
27
|
-
query = DataMapper::Query.new(repository, self, query) if query.kind_of?(Hash)
|
28
|
-
|
29
|
-
scope_stack << query
|
30
|
-
|
31
|
-
begin
|
32
|
-
return yield(query)
|
33
|
-
ensure
|
34
|
-
scope_stack.pop
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
# @api private
|
41
|
-
def merge_with_default_scope(query)
|
42
|
-
DataMapper::Query.new(query.repository, query.model, default_scope_for_query(query)).update(query)
|
43
|
-
end
|
44
|
-
|
45
|
-
# @api private
|
46
|
-
def scope_stack
|
47
|
-
scope_stack_for = Thread.current[:dm_scope_stack] ||= {}
|
48
|
-
scope_stack_for[self] ||= []
|
49
|
-
end
|
50
|
-
|
51
|
-
# @api private
|
52
|
-
def default_scope_for_query(query)
|
53
|
-
repository_name = query.repository.name
|
54
|
-
default_repository_name = query.model.default_repository_name
|
55
|
-
self.default_scope(default_repository_name).merge(self.default_scope(repository_name))
|
56
|
-
end
|
57
|
-
end # module Scope
|
58
|
-
end # module DataMapper
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class Array
|
2
|
-
|
3
|
-
##
|
4
|
-
# atm it assumes self is an array of [key,value]-arrays
|
5
|
-
# this is just a better way to make hashes than Hash[*array.flatten]
|
6
|
-
# since you cannot flatten only one level in ruby 1.8.6
|
7
|
-
#
|
8
|
-
def to_hash
|
9
|
-
h = {}
|
10
|
-
self.each{ |k,v| h[k] = v }
|
11
|
-
h
|
12
|
-
end
|
13
|
-
end # class Symbol
|
@@ -1,8 +0,0 @@
|
|
1
|
-
module DataMapper
|
2
|
-
module Assertions
|
3
|
-
def assert_kind_of(name, value, *klasses)
|
4
|
-
klasses.each { |k| return if value.kind_of?(k) }
|
5
|
-
raise ArgumentError, "+#{name}+ should be #{klasses.map { |k| k.name } * ' or '}, but was #{value.class.name}", caller(2)
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end # module DataMapper
|
@@ -1,23 +0,0 @@
|
|
1
|
-
#Some useful errors types
|
2
|
-
module DataMapper
|
3
|
-
class ValidationError < StandardError; end
|
4
|
-
|
5
|
-
class ObjectNotFoundError < StandardError; end
|
6
|
-
|
7
|
-
class MaterializationError < StandardError; end
|
8
|
-
|
9
|
-
class RepositoryNotSetupError < StandardError; end
|
10
|
-
|
11
|
-
class IncompleteResourceError < StandardError; end
|
12
|
-
|
13
|
-
class PersistenceError < StandardError; end
|
14
|
-
|
15
|
-
class PluginNotFoundError < StandardError; end
|
16
|
-
end # module DataMapper
|
17
|
-
|
18
|
-
class StandardError
|
19
|
-
# Displays the specific error message and the backtrace associated with it.
|
20
|
-
def display
|
21
|
-
"#{message}\n\t#{backtrace.join("\n\t")}"
|
22
|
-
end
|
23
|
-
end # class StandardError
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Kernel
|
2
|
-
# Delegates to DataMapper::repository.
|
3
|
-
# Will not overwrite if a method of the same name is pre-defined.
|
4
|
-
def repository(*args)
|
5
|
-
if block_given?
|
6
|
-
DataMapper.repository(*args) { |*block_args| yield(*block_args) }
|
7
|
-
else
|
8
|
-
DataMapper.repository(*args)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end # module Kernel
|
@@ -1,41 +0,0 @@
|
|
1
|
-
class Symbol
|
2
|
-
def gt
|
3
|
-
DataMapper::Query::Operator.new(self, :gt)
|
4
|
-
end
|
5
|
-
|
6
|
-
def gte
|
7
|
-
DataMapper::Query::Operator.new(self, :gte)
|
8
|
-
end
|
9
|
-
|
10
|
-
def lt
|
11
|
-
DataMapper::Query::Operator.new(self, :lt)
|
12
|
-
end
|
13
|
-
|
14
|
-
def lte
|
15
|
-
DataMapper::Query::Operator.new(self, :lte)
|
16
|
-
end
|
17
|
-
|
18
|
-
def not
|
19
|
-
DataMapper::Query::Operator.new(self, :not)
|
20
|
-
end
|
21
|
-
|
22
|
-
def eql
|
23
|
-
DataMapper::Query::Operator.new(self, :eql)
|
24
|
-
end
|
25
|
-
|
26
|
-
def like
|
27
|
-
DataMapper::Query::Operator.new(self, :like)
|
28
|
-
end
|
29
|
-
|
30
|
-
def in
|
31
|
-
DataMapper::Query::Operator.new(self, :in)
|
32
|
-
end
|
33
|
-
|
34
|
-
def asc
|
35
|
-
DataMapper::Query::Operator.new(self, :asc)
|
36
|
-
end
|
37
|
-
|
38
|
-
def desc
|
39
|
-
DataMapper::Query::Operator.new(self, :desc)
|
40
|
-
end
|
41
|
-
end # class Symbol
|
data/lib/dm-core/support.rb
DELETED
data/lib/dm-core/type_map.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
# TODO: move to dm-more/dm-migrations
|
2
|
-
|
3
|
-
module DataMapper
|
4
|
-
class TypeMap
|
5
|
-
|
6
|
-
attr_accessor :parent, :chains
|
7
|
-
|
8
|
-
def initialize(parent = nil, &blk)
|
9
|
-
@parent, @chains = parent, {}
|
10
|
-
|
11
|
-
blk.call(self) unless blk.nil?
|
12
|
-
end
|
13
|
-
|
14
|
-
def map(type)
|
15
|
-
@chains[type] ||= TypeChain.new
|
16
|
-
end
|
17
|
-
|
18
|
-
def lookup(type)
|
19
|
-
if type_mapped?(type)
|
20
|
-
lookup_from_map(type)
|
21
|
-
else
|
22
|
-
lookup_by_type(type)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def lookup_from_map(type)
|
27
|
-
lookup_from_parent(type).merge(map(type).translate)
|
28
|
-
end
|
29
|
-
|
30
|
-
def lookup_from_parent(type)
|
31
|
-
if !@parent.nil? && @parent.type_mapped?(type)
|
32
|
-
@parent[type]
|
33
|
-
else
|
34
|
-
{}
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# @raise <DataMapper::TypeMap::Error> if the type is not a default primitive or has a type map entry.
|
39
|
-
def lookup_by_type(type)
|
40
|
-
raise DataMapper::TypeMap::Error.new(type) unless type.respond_to?(:primitive) && !type.primitive.nil?
|
41
|
-
|
42
|
-
lookup(type.primitive).merge(Type::PROPERTY_OPTIONS.inject({}) {|h, k| h[k] = type.send(k); h})
|
43
|
-
end
|
44
|
-
|
45
|
-
alias [] lookup
|
46
|
-
|
47
|
-
def type_mapped?(type)
|
48
|
-
@chains.has_key?(type) || (@parent.nil? ? false : @parent.type_mapped?(type))
|
49
|
-
end
|
50
|
-
|
51
|
-
class TypeChain
|
52
|
-
attr_accessor :primitive, :attributes
|
53
|
-
|
54
|
-
def initialize
|
55
|
-
@attributes = {}
|
56
|
-
end
|
57
|
-
|
58
|
-
def to(primitive)
|
59
|
-
@primitive = primitive
|
60
|
-
self
|
61
|
-
end
|
62
|
-
|
63
|
-
def with(attributes)
|
64
|
-
raise "method 'with' expects a hash" unless attributes.kind_of?(Hash)
|
65
|
-
@attributes.merge!(attributes)
|
66
|
-
self
|
67
|
-
end
|
68
|
-
|
69
|
-
def translate
|
70
|
-
@attributes.merge((@primitive.nil? ? {} : {:primitive => @primitive}))
|
71
|
-
end
|
72
|
-
end # class TypeChain
|
73
|
-
|
74
|
-
class Error < StandardError
|
75
|
-
def initialize(type)
|
76
|
-
super("Type #{type} must have a default primitive or type map entry")
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end # class TypeMap
|
80
|
-
end # module DataMapper
|
data/lib/dm-core/types.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
dir = Pathname(__FILE__).dirname.expand_path / 'types'
|
2
|
-
|
3
|
-
require dir / 'boolean'
|
4
|
-
require dir / 'discriminator'
|
5
|
-
require dir / 'text'
|
6
|
-
require dir / 'paranoid_datetime'
|
7
|
-
require dir / 'paranoid_boolean'
|
8
|
-
require dir / 'object'
|
9
|
-
require dir / 'serial'
|
10
|
-
|
11
|
-
unless defined?(DM)
|
12
|
-
DM = DataMapper::Types
|
13
|
-
end
|
14
|
-
|
15
|
-
module DataMapper
|
16
|
-
module Resource
|
17
|
-
include Types
|
18
|
-
end # module Resource
|
19
|
-
end # module DataMapper
|
data/script/all
DELETED