proformaxml 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c50e2e72dc70055556ef14a9be087d9f557aeac25eb4c8a53c28f1132baaf20e
4
- data.tar.gz: 392e5f8391908e2221a423b8ae69d97e25edc6ea184ed987e59487d9acf9a715
3
+ metadata.gz: 81e1724c3c9498d52025b18b5f3e2830fa10c499bcc9a064470f265d6ed9ba34
4
+ data.tar.gz: 4b7499f6e605ba8dae8ad23e149a06e7e78fa08f91a14f3e8803e70140b02cdc
5
5
  SHA512:
6
- metadata.gz: aff94d81a98f927cd04cd85b9c0fed428fb93e0496e968d0079152e2a50269e3b6cced82a17cec7002ee0fb0fbc3c964a7a85513f597541f4ade0e91eeb3bc7d
7
- data.tar.gz: e54b57f55f6731036eb9659357d734e991f2f3dafd63083e56119d73be12cea07ba779ead3c7e5c921ccbaf4e258d3042054281bc2a21720c00a3f2288b70a92
6
+ metadata.gz: c47047c96d5fb1c23233c67bd165a6b088e643bc9b6032c8107afd1e32d8d3cb9c4d2342661bd0b5b2b9da38fee368a058dc2fdfa2aabd34889f49c3e9817c21
7
+ data.tar.gz: 18e38170e845ad6e148ce0de1f621e57c3b360a19c7e3a875d8be90e1dfaf94fc085aacdd18ab16d6a587116261426e1f6de6939a351d5fdb0a683e218c7ed1d
@@ -0,0 +1,5 @@
1
+ # factory bot cop settings
2
+
3
+ # We need to define own IDs, since we do not store objects in a database with ActiveRecord.
4
+ FactoryBot/IdSequence:
5
+ Enabled: false
data/.rubocop/rspec.yml CHANGED
@@ -25,3 +25,11 @@ RSpec/NestedGroups:
25
25
 
26
26
  RSpec/IndexedLet:
27
27
  Max: 2
28
+
29
+ RSpec/FilePath:
30
+ CustomTransform:
31
+ ProformaXML: proformaxml
32
+
33
+ RSpec/SpecFilePathFormat:
34
+ CustomTransform:
35
+ ProformaXML: proformaxml
data/.rubocop.yml CHANGED
@@ -5,6 +5,7 @@ require:
5
5
  - rubocop-rspec
6
6
 
7
7
  inherit_from:
8
+ - .rubocop/factory-bot.yml
8
9
  - .rubocop/layout.yml
9
10
  - .rubocop/lint.yml
10
11
  - .rubocop/metrics.yml
@@ -24,7 +25,3 @@ AllCops:
24
25
  - 'tmp/**/*'
25
26
  - 'out/**/*'
26
27
  - 'coverage/**/*'
27
-
28
- RSpec/FilePath:
29
- CustomTransform:
30
- ProformaXML: proformaxml
data/Gemfile CHANGED
@@ -16,7 +16,6 @@ gem 'rspec'
16
16
  gem 'rspec-collection_matchers'
17
17
  gem 'rspec-github'
18
18
  gem 'rubocop'
19
- gem 'rubocop-factory_bot'
20
19
  gem 'rubocop-performance'
21
20
  gem 'rubocop-rails'
22
21
  gem 'rubocop-rspec'
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- proformaxml (1.0.0)
4
+ proformaxml (1.1.0)
5
5
  activemodel (>= 5.2.3, < 8.0.0)
6
6
  activesupport (>= 5.2.3, < 8.0.0)
7
- dachsfisch (>= 0.1.0, < 1.0.0)
7
+ dachsfisch (>= 0.2.0, < 1.0.0)
8
8
  nokogiri (>= 1.10.2, < 2.0.0)
9
9
  rubyzip (>= 1.2.2, < 3.0.0)
10
10
 
@@ -23,15 +23,15 @@ GEM
23
23
  byebug (11.1.3)
24
24
  coderay (1.1.3)
25
25
  concurrent-ruby (1.2.2)
26
- dachsfisch (0.1.0)
26
+ dachsfisch (0.2.0)
27
27
  nokogiri (>= 1.14.1, < 2.0.0)
28
28
  diff-lcs (1.5.0)
29
29
  docile (1.4.0)
30
30
  factory_bot (6.3.0)
31
31
  activesupport (>= 5.0.0)
32
- ffi (1.15.5)
32
+ ffi (1.16.1)
33
33
  formatador (1.1.0)
34
- guard (2.18.0)
34
+ guard (2.18.1)
35
35
  formatador (>= 0.2.4)
36
36
  listen (>= 2.7, < 4.0)
37
37
  lumberjack (>= 1.0.12, < 2.0)
@@ -86,7 +86,7 @@ GEM
86
86
  rspec-core (~> 3.12.0)
87
87
  rspec-expectations (~> 3.12.0)
88
88
  rspec-mocks (~> 3.12.0)
89
- rspec-collection_matchers (1.2.0)
89
+ rspec-collection_matchers (1.2.1)
90
90
  rspec-expectations (>= 2.99.0.beta1)
91
91
  rspec-core (3.12.2)
92
92
  rspec-support (~> 3.12.0)
@@ -99,7 +99,7 @@ GEM
99
99
  diff-lcs (>= 1.2.0, < 2.0)
100
100
  rspec-support (~> 3.12.0)
101
101
  rspec-support (3.12.1)
102
- rubocop (1.56.2)
102
+ rubocop (1.56.4)
103
103
  base64 (~> 0.1.1)
104
104
  json (~> 2.3)
105
105
  language_server-protocol (>= 3.17.0)
@@ -113,18 +113,18 @@ GEM
113
113
  unicode-display_width (>= 2.4.0, < 3.0)
114
114
  rubocop-ast (1.29.0)
115
115
  parser (>= 3.2.1.0)
116
- rubocop-capybara (2.18.0)
116
+ rubocop-capybara (2.19.0)
117
117
  rubocop (~> 1.41)
118
- rubocop-factory_bot (2.23.1)
118
+ rubocop-factory_bot (2.24.0)
119
119
  rubocop (~> 1.33)
120
- rubocop-performance (1.19.0)
120
+ rubocop-performance (1.19.1)
121
121
  rubocop (>= 1.7.0, < 2.0)
122
122
  rubocop-ast (>= 0.4.0)
123
- rubocop-rails (2.20.2)
123
+ rubocop-rails (2.21.2)
124
124
  activesupport (>= 4.2.0)
125
125
  rack (>= 1.1)
126
126
  rubocop (>= 1.33.0, < 2.0)
127
- rubocop-rspec (2.23.2)
127
+ rubocop-rspec (2.24.1)
128
128
  rubocop (~> 1.33)
129
129
  rubocop-capybara (~> 2.17)
130
130
  rubocop-factory_bot (~> 2.22)
@@ -140,7 +140,7 @@ GEM
140
140
  thor (1.2.2)
141
141
  tzinfo (2.0.6)
142
142
  concurrent-ruby (~> 1.0)
143
- unicode-display_width (2.4.2)
143
+ unicode-display_width (2.5.0)
144
144
 
145
145
  PLATFORMS
146
146
  ruby
@@ -158,7 +158,6 @@ DEPENDENCIES
158
158
  rspec-collection_matchers
159
159
  rspec-github
160
160
  rubocop
161
- rubocop-factory_bot
162
161
  rubocop-performance
163
162
  rubocop-rails
164
163
  rubocop-rspec
@@ -27,55 +27,31 @@ module ProformaXML
27
27
  xml.send(:'test-configuration') do
28
28
  add_filerefs(xml, test) if test.files
29
29
  add_dachsfisch_node(xml, test.configuration)
30
- if test.meta_data
31
- xml.send(:'test-meta-data') do
32
- meta_data(xml, test.meta_data)
33
- end
34
- end
30
+ add_dachsfisch_node(xml, test.meta_data)
35
31
  end
36
32
  end
37
33
 
38
- def inner_meta_data(xml, namespace, data)
39
- data.each do |key, value|
40
- case value.class.name
41
- when 'Hash'
42
- # underscore is used to disambiguate tag names from ruby methods
43
- xml[namespace].send("#{key}_") do |meta_data_xml|
44
- inner_meta_data(meta_data_xml, namespace, value)
45
- end
46
- else
47
- xml[namespace].send("#{key}_", value)
48
- end
34
+ def add_dachsfisch_node(xml, dachsfisch_node, node_name_fallback = nil)
35
+ if dachsfisch_node.blank?
36
+ xml.send(node_name_fallback, '') if node_name_fallback.present?
37
+ return
49
38
  end
50
- end
51
-
52
- def meta_data(xml, meta_data)
53
- meta_data.each do |namespace, data|
54
- inner_meta_data(xml, namespace, data)
55
- end
56
- end
57
-
58
- def add_dachsfisch_node(xml, dachsfisch_node)
59
- return if dachsfisch_node.nil?
60
-
61
39
  xml_snippet = Dachsfisch::JSON2XMLConverter.perform(json: dachsfisch_node.to_json)
62
- dachsfisch_node.flat_map {|_, val| val['@xmlns'].to_a }.uniq.each do |namespace|
63
- xml.doc.root.add_namespace(namespace[0], namespace[1]) unless namespace[0] == '$'
64
- end
40
+ add_namespaces_for_dachsfisch_node(dachsfisch_node, xml)
65
41
 
66
42
  xml << xml_snippet
67
43
  end
68
44
 
69
- def add_namespaces_to_header(header, custom_namespaces)
70
- custom_namespaces.each do |namespace|
71
- header["xmlns:#{namespace[:prefix]}"] = namespace[:uri]
72
- end
73
- end
74
-
75
45
  def add_parent_uuid_and_lang_to_header(header)
76
46
  header['lang'] = @task.language if @task.language.present?
77
47
  header['parent-uuid'] = @task.parent_uuid if @task.parent_uuid.present?
78
48
  end
49
+
50
+ def add_namespaces_for_dachsfisch_node(dachsfisch_node, xml)
51
+ dachsfisch_node.flat_map {|_, val| val['@xmlns'].to_a }.uniq.each do |namespace|
52
+ xml.doc.root.add_namespace(namespace[0], namespace[1]) unless namespace[0] == '$'
53
+ end
54
+ end
79
55
  end
80
56
  end
81
57
  end
@@ -60,7 +60,7 @@ module ProformaXML
60
60
  test.files = test_files_from_test_configuration(test_configuration_node)
61
61
  test.configuration = extra_configuration_from_test_configuration(test_configuration_node)
62
62
  meta_data_node = test_node.xpath('xmlns:test-configuration').xpath('xmlns:test-meta-data')
63
- test.meta_data = meta_data(meta_data_node, use_namespace: true) if meta_data_node.present?
63
+ test.meta_data = convert_xml_node_to_json(meta_data_node) if meta_data_node.present?
64
64
  end
65
65
 
66
66
  def extra_configuration_from_test_configuration(test_configuration_node)
@@ -78,32 +78,22 @@ module ProformaXML
78
78
  files_from_filerefs(test_configuration_node.search('filerefs'))
79
79
  end
80
80
 
81
- def meta_data(any_data_node, use_namespace: false)
82
- # use_namespace forces the use of the namespace as hash key - it should only be used at the entry of the recursion
83
- {}.tap do |any_data|
84
- any_data_node.children.each do |node|
85
- key = (use_namespace ? node.namespace.prefix : any_data_node.name).to_sym
86
- any_data[key] = if node.node_type == Nokogiri::XML::Node::TEXT_NODE
87
- node.text
88
- else
89
- # preserve any existing data in the nested hash
90
- (any_data[key] || {}).merge meta_data(node)
91
- end
92
- end
93
- end
94
- end
95
-
96
81
  private
97
82
 
98
83
  def convert_xml_node_to_json(any_node)
99
84
  xml_snippet = Nokogiri::XML::DocumentFragment.new(Nokogiri::XML::Document.new, any_node)
100
- unless any_node.namespace.prefix.nil?
101
- xml_snippet.children.first.add_namespace_definition(any_node.namespace.prefix,
102
- any_node.namespace.href)
85
+ all_namespaces(any_node).each do |namespace|
86
+ xml_snippet.children.first.add_namespace_definition(namespace[:prefix], namespace[:href])
103
87
  end
104
88
  JSON.parse(Dachsfisch::XML2JSONConverter.perform(xml: xml_snippet.to_xml))
105
89
  end
106
90
 
91
+ def all_namespaces(node)
92
+ node.xpath('.|.//*').map(&:namespace).reject do |ns|
93
+ ns.prefix.nil?
94
+ end.map {|ns| {prefix: ns.prefix, href: ns.href} }.uniq
95
+ end
96
+
107
97
  def value_from_node(name, node, attribute)
108
98
  xml_name = name.is_a?(Array) ? name[0] : name
109
99
  attribute ? node.attribute(xml_name)&.value : node.xpath("xmlns:#{xml_name}").text
@@ -6,10 +6,9 @@ module ProformaXML
6
6
  class Exporter
7
7
  include ProformaXML::Helpers::ExportHelpers
8
8
 
9
- def initialize(task:, custom_namespaces: [], version: nil)
9
+ def initialize(task:, version: nil)
10
10
  @files = {}
11
11
  @task = task
12
- @custom_namespaces = custom_namespaces
13
12
  @version = version || SCHEMA_VERSIONS.first
14
13
  add_placeholders if @version == '2.0'
15
14
  end
@@ -22,9 +21,9 @@ module ProformaXML
22
21
  doc = Nokogiri::XML(xmldoc)
23
22
  errors = validate(doc)
24
23
 
24
+ # File.binwrite('../testfile.zip', write_to_zip(xmldoc).string)
25
25
  raise PostGenerateValidationError.new(errors) if errors.any?
26
26
 
27
- # File.binwrite('../testfile.zip', write_to_zip(xmldoc).string)
28
27
  write_to_zip(xmldoc)
29
28
  end
30
29
 
@@ -38,7 +37,7 @@ module ProformaXML
38
37
  xml.proglang({version: @task.proglang&.dig(:version)}, @task.proglang&.dig(:name))
39
38
 
40
39
  add_objects_to_xml(xml)
41
- add_meta_data(xml)
40
+ add_dachsfisch_node(xml, @task.meta_data, 'meta-data')
42
41
  end
43
42
  end
44
43
 
@@ -46,10 +45,6 @@ module ProformaXML
46
45
  xml.send(:'internal-description', internal_description) if internal_description.present?
47
46
  end
48
47
 
49
- def add_meta_data(xml)
50
- xml.send(:'meta-data') { meta_data(xml, @task.meta_data) }
51
- end
52
-
53
48
  def add_objects_to_xml(xml)
54
49
  add_dachsfisch_node(xml, @task.submission_restrictions)
55
50
  xml.files { files(xml) }
@@ -117,7 +112,6 @@ module ProformaXML
117
112
  'xmlns' => "urn:proforma:v#{@version}",
118
113
  'uuid' => @task.uuid,
119
114
  }.tap do |header|
120
- add_namespaces_to_header(header, @custom_namespaces)
121
115
  add_parent_uuid_and_lang_to_header(header)
122
116
  end
123
117
  end
@@ -26,7 +26,7 @@ module ProformaXML
26
26
  @task_node = @doc.xpath('/xmlns:task')
27
27
 
28
28
  set_data
29
- {task: @task, custom_namespaces: @custom_namespaces}
29
+ @task
30
30
  end
31
31
 
32
32
  private
@@ -38,7 +38,6 @@ module ProformaXML
38
38
  end
39
39
 
40
40
  def set_data
41
- set_namespaces
42
41
  set_base_data
43
42
  set_files
44
43
  set_model_solutions
@@ -47,10 +46,6 @@ module ProformaXML
47
46
  set_extra_data
48
47
  end
49
48
 
50
- def set_namespaces
51
- @custom_namespaces = @doc.namespaces.except('xmlns').map {|k, v| {prefix: k[6..], uri: v} }
52
- end
53
-
54
49
  def set_base_data
55
50
  set_value_from_xml(object: @task, node: @task_node, name: 'title')
56
51
  set_value_from_xml(object: @task, node: @task_node, name: 'description')
@@ -83,8 +78,8 @@ module ProformaXML
83
78
  end
84
79
 
85
80
  def set_meta_data
86
- meta_data_node = @task_node.xpath('xmlns:meta-data')
87
- @task.meta_data = meta_data(meta_data_node, use_namespace: true) if meta_data_node.text.present?
81
+ meta_data_node = @task_node.xpath('xmlns:meta-data').first
82
+ @task.meta_data = convert_xml_node_to_json(meta_data_node) if meta_data_node.text.present?
88
83
  end
89
84
 
90
85
  def set_extra_data
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProformaXML
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
data/proformaxml.gemspec CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.add_dependency 'activemodel', '>= 5.2.3', '< 8.0.0'
31
31
  spec.add_dependency 'activesupport', '>= 5.2.3', '< 8.0.0'
32
- spec.add_dependency 'dachsfisch', '>= 0.1.0', '< 1.0.0'
32
+ spec.add_dependency 'dachsfisch', '>= 0.2.0', '< 1.0.0'
33
33
  spec.add_dependency 'nokogiri', '>= 1.10.2', '< 2.0.0'
34
34
  spec.add_dependency 'rubyzip', '>= 1.2.2', '< 3.0.0'
35
35
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proformaxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karol
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-11 00:00:00.000000000 Z
11
+ date: 2023-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -56,7 +56,7 @@ dependencies:
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 0.1.0
59
+ version: 0.2.0
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
62
  version: 1.0.0
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 0.1.0
69
+ version: 0.2.0
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
72
  version: 1.0.0
@@ -119,6 +119,7 @@ extra_rdoc_files: []
119
119
  files:
120
120
  - ".rspec"
121
121
  - ".rubocop.yml"
122
+ - ".rubocop/factory-bot.yml"
122
123
  - ".rubocop/layout.yml"
123
124
  - ".rubocop/lint.yml"
124
125
  - ".rubocop/metrics.yml"