paulcarey-relaxdb 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/relaxdb/document.rb +41 -24
- metadata +2 -2
data/Rakefile
CHANGED
data/lib/relaxdb/document.rb
CHANGED
@@ -181,8 +181,11 @@ module RelaxDB
|
|
181
181
|
id = instance_variable_get("@#{relationship}_id".to_sym)
|
182
182
|
s << ", #{relationship}_id: #{id}" if id
|
183
183
|
end
|
184
|
+
s << ", errors: #{errors.inspect}" unless errors.empty?
|
184
185
|
s << ">"
|
185
186
|
end
|
187
|
+
|
188
|
+
alias_method :to_s, :inspect
|
186
189
|
|
187
190
|
def to_json
|
188
191
|
data = {}
|
@@ -197,7 +200,7 @@ module RelaxDB
|
|
197
200
|
data["class"] = self.class.name
|
198
201
|
data.to_json
|
199
202
|
end
|
200
|
-
|
203
|
+
|
201
204
|
# Order changed as of 30/10/2008 to be consistent with ActiveRecord
|
202
205
|
# Not yet sure of final implemention for hooks - may lean more towards DM than AR
|
203
206
|
def save(*validation_skip_list)
|
@@ -219,34 +222,48 @@ module RelaxDB
|
|
219
222
|
end
|
220
223
|
|
221
224
|
def validates?(*skip_list)
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
@errors[prop] = send("#{prop}_validation_msg", prop_val) rescue "validation_msg_exception:invalid:#{prop_val}"
|
231
|
-
else
|
232
|
-
@errors[prop] = "invalid:#{prop}"
|
233
|
-
end
|
234
|
-
end
|
235
|
-
total_success &= success
|
236
|
-
end
|
237
|
-
end
|
225
|
+
props = properties - skip_list
|
226
|
+
prop_vals = props.map { |prop| instance_variable_get("@#{prop}") }
|
227
|
+
|
228
|
+
rels = self.class.belongs_to_rels.keys - skip_list
|
229
|
+
rel_vals = rels.map { |rel| instance_variable_get("@#{rel}_id") }
|
230
|
+
|
231
|
+
att_names = props + rels
|
232
|
+
att_vals = prop_vals + rel_vals
|
238
233
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
total_success &= success
|
234
|
+
total_success = true
|
235
|
+
att_names.each_index do |i|
|
236
|
+
att_name, att_val = att_names[i], att_vals[i]
|
237
|
+
if methods.include? "validate_#{att_name}"
|
238
|
+
total_success &= validate_att(att_name, att_val)
|
245
239
|
end
|
246
240
|
end
|
247
|
-
|
241
|
+
|
248
242
|
total_success
|
249
243
|
end
|
244
|
+
|
245
|
+
def validate_att(att_name, att_val)
|
246
|
+
begin
|
247
|
+
success = send("validate_#{att_name}", att_val)
|
248
|
+
rescue => e
|
249
|
+
RelaxDB.logger.warn("Validating #{att_name} with #{att_val} raised #{e}")
|
250
|
+
succes = false
|
251
|
+
end
|
252
|
+
|
253
|
+
unless success
|
254
|
+
if methods.include? "#{att_name}_validation_msg"
|
255
|
+
begin
|
256
|
+
@errors[att_name] = send("#{att_name}_validation_msg", att_val)
|
257
|
+
rescue => e
|
258
|
+
RelaxDB.logger.warn("Validation_msg for #{att_name} with #{att_val} raised #{e}")
|
259
|
+
@errors[att_name] = "validation_msg_exception:invalid:#{att_name_val}"
|
260
|
+
end
|
261
|
+
else
|
262
|
+
@errors[att_name] = "invalid:#{att_val}"
|
263
|
+
end
|
264
|
+
end
|
265
|
+
success
|
266
|
+
end
|
250
267
|
|
251
268
|
def new_document?
|
252
269
|
@_rev.nil?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paulcarey-relaxdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Carey
|
@@ -9,7 +9,7 @@ autorequire: relaxdb
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-08 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|