datoki 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/VERSION +1 -1
  4. data/lib/datoki.rb +23 -34
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 397ce11ce7b856de259198ac22633a0624fa971e
4
- data.tar.gz: bb53e10c2760b096e7a56fee2a89fc93cbac2b22
3
+ metadata.gz: f8ba5eae546ee0b466bbb634b3b05203ad3cfef1
4
+ data.tar.gz: c5fca1d1cc64342d30538e9850b16c2995d55dd2
5
5
  SHA512:
6
- metadata.gz: 48265561168ce8dd52640b1dfd5b2a709cc6201e052922b3a664377590b4ca6b1b8665f704b44a1c00811d030823cef13302bc698998e106ac6889f62decea2d
7
- data.tar.gz: 7a0ab44c107a3abea4d8173fed8e54a590e7ba9453aca9c27959b7547c2919141c53da09fdea10bfcde9e0c6a69f126a8159e04fcf2e7d8b570b202e69d53fa3
6
+ metadata.gz: f356726aa8abe2b29ec6bfd0ff86594d81621e8bdbde5276d60aec70dc85aab1288c13893a6505f053f14d1c8d57f049707c39fdb93ce1db1fbfc51c33f90d7c
7
+ data.tar.gz: 49c0f8bbbd20b2785c2be44bea06f650e76cc01a8b30783c524fc2ab278ff3a4ae94010a74bf3b467ee1d3aeab341647a958aaedd9573565ea3c653d4a2d09a2
data/README.md CHANGED
@@ -20,7 +20,7 @@ A Ruby gem for managing validation and records using PostgreSQL.
20
20
  on :create_or_update? do
21
21
 
22
22
  on :create? do
23
- clean :name!, :desc
23
+ clean :name, :desc
24
24
  end
25
25
 
26
26
  on :update? do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.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
- if !clean.has_key?(k) && !meta[:allow][:null] && !meta[:primary_key]
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
- if args.empty?
532
- @clean ||= begin
533
- h = {}
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 = args.first
545
- required = false
547
+ name = args.first
546
548
 
547
- if self.class.fields_as_required[name]
548
- name = self.class.fields_as_required[name]
549
- required = true
550
- end
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
- # === Skip this if nothing is set and is null-able:
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
- clean[name] = @raw[name] unless clean.has_key?(name)
557
+ # === Skip cleaning if key is not set:
558
+ return nil unless @clean.has_key?(name)
567
559
 
568
- # === Should we let the DB set the value?
569
- if self.class.schema[name] && self.class.schema[name][:default] && (!clean.has_key?(name) || !clean[name])
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]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datoki
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - da99