datoki 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/VERSION +1 -1
- data/lib/datoki.rb +23 -34
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8ba5eae546ee0b466bbb634b3b05203ad3cfef1
|
4
|
+
data.tar.gz: c5fca1d1cc64342d30538e9850b16c2995d55dd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f356726aa8abe2b29ec6bfd0ff86594d81621e8bdbde5276d60aec70dc85aab1288c13893a6505f053f14d1c8d57f049707c39fdb93ce1db1fbfc51c33f90d7c
|
7
|
+
data.tar.gz: 49c0f8bbbd20b2785c2be44bea06f650e76cc01a8b30783c524fc2ab278ff3a4ae94010a74bf3b467ee1d3aeab341647a958aaedd9573565ea3c653d4a2d09a2
|
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.1
|
data/lib/datoki.rb
CHANGED
@@ -468,7 +468,6 @@ module Datoki
|
|
468
468
|
@data.default_proc = Key_Not_Found
|
469
469
|
else
|
470
470
|
@raw = unknown
|
471
|
-
@raw.default_proc = Key_Not_Found
|
472
471
|
end
|
473
472
|
end
|
474
473
|
|
@@ -498,11 +497,17 @@ module Datoki
|
|
498
497
|
}
|
499
498
|
end
|
500
499
|
|
500
|
+
schema = self.class.schema
|
501
501
|
if create?
|
502
|
+
# === Did the programmer forget to set the value?:
|
502
503
|
self.class.fields.each { |k, meta|
|
503
|
-
|
504
|
+
has_default = schema[k] && schema[k][:default]
|
505
|
+
if clean[k].nil? && !meta[:allow][:null] && !meta[:primary_key] && !has_default
|
504
506
|
fail ArgumentError, "#{k.inspect} is not set."
|
505
507
|
end
|
508
|
+
|
509
|
+
# === Should we let the DB set the value?
|
510
|
+
@clean.delete(k) if @clean[k].nil? && has_default
|
506
511
|
}
|
507
512
|
end
|
508
513
|
|
@@ -528,48 +533,32 @@ module Datoki
|
|
528
533
|
end
|
529
534
|
|
530
535
|
def clean *args
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
h.default_proc = Key_Not_Found
|
535
|
-
h
|
536
|
-
end
|
537
|
-
return @clean
|
538
|
-
end
|
536
|
+
@clean ||= {}
|
537
|
+
|
538
|
+
return @clean if args.empty?
|
539
539
|
|
540
|
+
# === Handle required fields:
|
541
|
+
# Example:
|
542
|
+
# :name!, :age!
|
540
543
|
if args.size > 1
|
541
544
|
return args.each { |f| clean f }
|
542
545
|
end
|
543
546
|
|
544
|
-
name
|
545
|
-
required = false
|
547
|
+
name = args.first
|
546
548
|
|
547
|
-
if self.class.fields_as_required[name]
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
field_name(name)
|
553
|
-
f_meta = self.class.fields[name]
|
554
|
-
required = true if (!field[:allow][:null] && (!@raw.has_key?(name) || @raw[name] == nil))
|
555
|
-
|
556
|
-
# === Did the programmer forget to set the value?:
|
557
|
-
if required && (!@raw.has_key?(name) || @raw[name].nil?)
|
558
|
-
fail ArgumentError, "#{name.inspect} is not set."
|
549
|
+
if (real_name = self.class.fields_as_required[name]) && @raw[real_name].nil? && @clean[real_name].nil?
|
550
|
+
fail ArgumentError, "#{real_name.inspect} is not set."
|
551
|
+
else
|
552
|
+
name = real_name || name
|
559
553
|
end
|
560
554
|
|
561
|
-
|
562
|
-
if !required && field[:allow][:null] && !@raw.has_key?(name) && !clean.has_key?(name)
|
563
|
-
return nil
|
564
|
-
end
|
555
|
+
@clean[name] = @raw[name] if !clean.has_key?(name) && @raw.has_key?(name)
|
565
556
|
|
566
|
-
|
557
|
+
# === Skip cleaning if key is not set:
|
558
|
+
return nil unless @clean.has_key?(name)
|
567
559
|
|
568
|
-
|
569
|
-
|
570
|
-
clean.delete name
|
571
|
-
return self.class.schema[name][:default]
|
572
|
-
end
|
560
|
+
field_name(name)
|
561
|
+
f_meta = self.class.fields[name]
|
573
562
|
|
574
563
|
# === Strip the value:
|
575
564
|
if clean[name].is_a?(String) && field[:allow][:strip]
|