Class: Verify
- Inherits:
-
Object
- Object
- Verify
- Defined in:
- lib/verify/verify.rb
Class Method Summary collapse
- .IsVerified?(items = [], table_name = "") ⇒ Boolean
- .match_fields?(item = {}, table_name) ⇒ Boolean
- .switch_table(item = {}) ⇒ Object
- .table_names ⇒ Object
Class Method Details
.IsVerified?(items = [], table_name = "") ⇒ Boolean
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/verify/verify.rb', line 2 def self.IsVerified?(items=[],table_name="") if table_name == "" && items.size > 0 table_name = switch_table(items[0]) puts "验证:#{table_name}" elsif table_name != "" && items.size > 0 puts "验证:#{table_name}" if !match_fields?(items[0],table_name) return end end if table_name == "" puts "未匹配,不验证" end if table_name != "" kclass = Object.const_get $map_models[table_name] if kclass == nil puts "ERROR #{table_name} 验证 not Exist!" return true end items.each do |item| if !kclass.new(item).verify return false end end end return true end |
.match_fields?(item = {}, table_name) ⇒ Boolean
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/verify/verify.rb', line 57 def self.match_fields?(item={},table_name) if table_name == nil || table_name == "" return false end item_keys = JSON.parse(item.to_json).keys v = $map_models[table_name] if v == nil puts "ERROR #{table_name} not Exist!" return false end klass = Object.const_get v klass_keys = klass.fields # puts "----#{klass_keys}--" sub_keys1 = item_keys - klass_keys if sub_keys1.size > 0 puts "ERROR #{sub_keys1} do not belong #{table_name}" return false end sub_keys2 = klass_keys - item_keys if sub_keys2.size > 0 puts "ERROR #{sub_keys2} do not Exist!" return false end return true end |
.switch_table(item = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/verify/verify.rb', line 37 def self.switch_table(item={}) table_name = "" item_keys = JSON.parse(item.to_json).keys # puts "----#{item_keys}--" $map_models.each do |k,v| klass = Object.const_get v klass_keys = klass.fields # puts "----#{klass_keys}--" sub_keys = item_keys - klass_keys if sub_keys.size == 0 && item_keys.size == klass_keys.size return k end end return table_name end |
.table_names ⇒ Object
89 90 91 |
# File 'lib/verify/verify.rb', line 89 def self.table_names return $map_models.keys end |