circuitdata 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa1f26f00a6e37eddbd191f4c07e20cd6549403d
4
- data.tar.gz: 22e2442da385848cb8836ede71d6f747bf8f8cf9
3
+ metadata.gz: bcf321b8a7e8598d02416139e9c123515d6c2ab6
4
+ data.tar.gz: 6ebd5b1f5db47775a316ccdb8504ea415e726a9d
5
5
  SHA512:
6
- metadata.gz: 2c98b789d6a3299aa7494eefcf0b291be7aa7769015006d9984748f1c8ba39a282fe0ad997913dcb89e89a1f75fa231eac27d242a15ca7e07f8af619e65d16d0
7
- data.tar.gz: 8996afcb18cd0c8cd8d26c08dd53f637f12f0dd3932b37a414a1ccfae9915ae2e2d00545cf0598317e4411c371e0f8ff4562887ee17e65f6a9d6586906223870
6
+ metadata.gz: 9b4290b6fcf5f8cdf725f2ef2130699be3c57ba06aae883062c6bf969042ed96b60b1f8556fec7f64848f0d2ada9dc81b39cf61b2bc9ef81bd53ca06e571a232
7
+ data.tar.gz: 1b27bb2cb683881085ff3edccc53035c4cf21f9ab242573e86e16d0180547a57f6cae468c3bc47e439ebcaddb32796d9267c4d95e0a787c07e810920822eb2af
data/lib/circuitdata.rb CHANGED
@@ -13,7 +13,7 @@ module Circuitdata
13
13
  types << 'capabilities' unless wrapper&.dig(:capabilities).nil?
14
14
 
15
15
  products = wrapper&.dig(:products)
16
- product_names = products.nil? ? [] : products.keys# this will return all the product names
16
+ product_names = products.nil? ? [] : products.keys # this will return all the product names
17
17
  types << 'product' if product_names.any?
18
18
  # loop through the products
19
19
  products.each do |k, v|
@@ -101,20 +101,9 @@ module Circuitdata
101
101
  profile_default = File.join(File.dirname(__FILE__), '../test/test_data/testfile-profile-default.json')
102
102
  capabilities = File.join(File.dirname(__FILE__), '../test/test_data/testfile-capability.json')
103
103
 
104
- # TEST WITH NON SCHEMA COMPATIBLE JSON
105
- # puts 'testing validation with non schema compatible json'
106
- # puts Circuitdata.compatibility_checker(fail_product)
107
- # puts "\n"
108
-
109
- # TEST THE COMPATIBILITY CHECKER FUNCTION FIRST:
110
- puts "\nTesting compatibility_checker: - the capabilities"
111
- puts Circuitdata.compatibility_checker(product1, capabilities)
112
- puts "\n"
113
-
114
104
  # THEN TEST THE COMPARE FILES:
115
105
  puts "Testing file comparison"
116
- # file_hash = {product1: product1, product2: product2, restricted: profile_restricted, enforced: profile_enforced, default: profile_default, capability: capabilities}
117
- file_hash = {product1: product1, product2: product2, restricted: profile_restricted, enforced: profile_enforced, default: profile_default}
106
+ file_hash = {product1: product1, product2: product2, restricted: profile_restricted, enforced: profile_enforced, default: profile_default, capability: capabilities}
118
107
  Circuitdata.compare_files(file_hash, true)
119
108
  end
120
109
  end
@@ -45,12 +45,10 @@ class Circuitdata::CompatibilityChecker
45
45
  else
46
46
  check_hash = {}
47
47
  end
48
- # binding.pry
49
48
 
49
+ common_hash = schema.dig(:properties, :open_trade_transfer_package, :properties, :products, :patternProperties, :'^(?!generic$).*', :properties, :printed_circuits_fabrication_data, :properties)
50
50
  check_hash.each do |k, v|
51
51
  v.each do |kl1, vl1| # level 1
52
- common_hash = schema.dig(:properties, :open_trade_transfer_package, :properties, :products, :patternProperties, :'^(?!generic$).*', :properties, :printed_circuits_fabrication_data, :properties)
53
- # binding.pry
54
52
  common_hash[k.to_sym]||= {:type => 'object', :properties => {}}
55
53
  common_hash[:stackup][:properties][:specified][:properties][k.to_sym] ||= {:type => 'object', :properties => {}}
56
54
 
@@ -75,7 +73,7 @@ class Circuitdata::CompatibilityChecker
75
73
  new_hash = eval("{:enum => #{enum}}")
76
74
  end
77
75
  end
78
- when 'Numeric' # This is a normal string
76
+ when 'Numeric', 'Float' # This is a normal string
79
77
  case type
80
78
  when 'restricted'
81
79
  new_hash = {:not => {:allOf => [{:minimum => vl1.to_f},{:maximum => vl1.to_f}]}}
@@ -86,6 +84,8 @@ class Circuitdata::CompatibilityChecker
86
84
  common_hash[k.to_sym][:properties][kl1.to_sym] = new_hash
87
85
  common_hash[:stackup][:properties][:specified][:properties][k.to_sym][:properties][kl1.to_sym] = new_hash
88
86
  end if v.is_a? Hash
87
+
88
+ common_hash[k.to_sym][:additionalProperties] = false if (v.is_a?(Hash) && type == 'capabilities')
89
89
  end
90
90
 
91
91
  # perform validations
@@ -96,8 +96,6 @@ class Circuitdata::CompatibilityChecker
96
96
  @fh[:error] = true
97
97
  @fh[:message] = 'The product to check did not meet the requirements'
98
98
 
99
- # format the errors well here
100
-
101
99
  validation_errors.each do |error|
102
100
  error_array = []
103
101
  begin
@@ -8,7 +8,7 @@ class Circuitdata::FileComparer
8
8
  @default_column = nil
9
9
  @master_column = nil
10
10
  # Final hash
11
- @fh = {error: false, message: nil, conflict: false, product_name: nil, columns: nil, master_column: nil, rows: nil}
11
+ @fh = {error: false, message: nil, conflict: false, product_name: nil, columns: nil, rows: nil}
12
12
  end
13
13
 
14
14
  def compare
@@ -56,9 +56,11 @@ class Circuitdata::FileComparer
56
56
  end
57
57
  # Initialize the rows format - for all default profile items
58
58
  @default_column, file_v = @nh.select{|k, v| v[:types].include?("profile_defaults")}.first # this should only be a single file
59
- data = file_v[:data]
60
- product_hash = data.dig(:open_trade_transfer_package, :profiles, :defaults, :printed_circuits_fabrication_data)
61
- init_row_format(product_hash)
59
+ if @default_column.present?
60
+ data = file_v[:data]
61
+ product_hash = data.dig(:open_trade_transfer_package, :profiles, :defaults, :printed_circuits_fabrication_data)
62
+ init_row_format(product_hash)
63
+ end
62
64
  end
63
65
 
64
66
  # populate the @rows
@@ -95,6 +97,7 @@ class Circuitdata::FileComparer
95
97
 
96
98
  def process_row_hash(action)
97
99
  @rows.each do |k, v| # product elements level
100
+
98
101
  if v.is_a?(Hash)
99
102
  v.each do |kl1, vl1| # specification level
100
103
  value, conflict, conflicts_with, conflict_message = [], false, [], []
@@ -102,16 +105,16 @@ class Circuitdata::FileComparer
102
105
  conflicts = @nh.dig(kl2, :conflicts, @master_column)
103
106
  case action
104
107
  when 'populate'
105
- check = conflicts.any? && conflicts.dig(:rows, k, kl1).present?
108
+ conflict = conflicts.dig(:rows, k, kl1)
109
+ check = conflicts.any? && conflict.present?
106
110
  vl2[:value] = @nh.dig(kl2, :data, :open_trade_transfer_package, :products, @fh[:product_name].to_sym, :printed_circuits_fabrication_data, k, kl1)
107
111
  vl2[:conflict] = check unless vl2[:conflict] # update only when the status is false
108
- vl2[:conflicts_with] = check ? vl2[:conflicts_with] << @master_column : []
109
- vl2[:conflict_message] = check ? vl2[:conflict_message] + conflicts&.dig(:rows, k, kl1) : []
110
-
112
+ vl2[:conflicts_with] = check ? ((vl2[:conflicts_with] || []) << @master_column).uniq : vl2[:conflicts_with] || []
113
+ vl2[:conflict_message] = check ? ((vl2[:conflict_message] || []) + conflict).uniq : vl2[:conflict_message] || []
111
114
  # update master_column conflicts with
112
115
  if check
113
116
  master_row = @rows.dig(k, kl1, @master_column)
114
- master_row[:conflicts_with] = master_row[:conflicts_with] + conflicts.dig(:master_conflicts)
117
+ master_row[:conflicts_with] = (master_row[:conflicts_with] + conflicts.dig(:master_conflicts)).uniq
115
118
  master_row[:conflict] = true
116
119
  master_row[:conflict_message] = (master_row[:conflict_message] + vl2[:conflict_message]).uniq
117
120
  end
@@ -212,15 +215,45 @@ class Circuitdata::FileComparer
212
215
  errors.each do |k, v|
213
216
  folders_stack = k.split('/')
214
217
  folder, spec = folders_stack[5], folders_stack[6]
215
- summary[:rows][folder.to_sym] ||= {}
216
- spec_message = summary[:rows][folder.to_sym][spec.to_sym] || []
217
- summary[:rows][folder.to_sym][spec.to_sym] = spec_message+v
218
+ if folder.nil?
219
+ get_other_conflicts(summary[:rows], v, 'l1')
220
+ else
221
+ summary[:rows][folder.to_sym] ||= {}
222
+ if spec.nil?
223
+ get_other_conflicts(summary[:rows][folder.to_sym], v, 'l2')
224
+ else
225
+ summary[:rows][folder.to_sym][spec.to_sym] ||= []
226
+ summary[:rows][folder.to_sym][spec.to_sym] = summary[:rows][folder.to_sym][spec.to_sym] + v
227
+ end
228
+ end
218
229
  end if errors.any?
219
230
  end
220
231
  end
221
232
  summary
222
233
  end
223
234
 
235
+ def get_other_conflicts(hash, v, level)
236
+ hash[:not_allowed] ||= []
237
+ hash[:messages] ||= []
238
+ not_allowed, messages = [], []
239
+ if v.is_a? Array
240
+ # get items that are not allowed
241
+ msg = v.select{|e| e.include?('contains additional properties [')}.first
242
+ not_allowed = eval(msg[/properties(.*?)outside/m, 1]) rescue []
243
+ messages << "#{not_allowed.to_sentence} are not allowed" if not_allowed.any?
244
+ # get other conflicts
245
+ messages = messages + v.select{|e| !e.include?('contains additional properties [')}
246
+ end
247
+ if not_allowed.any? && level == 'l2'
248
+ not_allowed.each do |spec|
249
+ hash[spec.to_sym] ||= []
250
+ hash[spec.to_sym] = hash[spec.to_sym] << "#{spec} is not a allowed element"
251
+ end
252
+ end
253
+ hash[:not_allowed] = (hash[:not_allowed] + not_allowed).uniq
254
+ hash[:messages] = (hash[:messages] + messages).uniq
255
+ end
256
+
224
257
  def get_l1_hash(columns)
225
258
  l1_hash = {}
226
259
  columns.each{|c| l1_hash[c]={} }
@@ -1,3 +1,3 @@
1
1
  module Circuitdata
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circuitdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Lydersen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-20 00:00:00.000000000 Z
11
+ date: 2017-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema