xsd 2.6.0 → 2.6.2

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: 2a5aa03e831e5cf4e88780b18a4ef57217eff54a14e2138669672f33486ba8bd
4
- data.tar.gz: b6a9ab392e47192a6a286ffa7dc97c5f624c78d9ab117bdea67e11f801c39363
3
+ metadata.gz: d3f894631bb4ecfab0ab93c8b67f1a4d2d85dc88aeef5c69890e424c018ea7a0
4
+ data.tar.gz: 6be2dfdee0a06f955d80ba57cbc39739fa6c09c06d6af80d194e77ccf32c8797
5
5
  SHA512:
6
- metadata.gz: a031bc3a3947708a8f6f8e4add4040853f9f8b62cd3465de56421600d9fc2d2b7c45b163efe239c7486dce05bf0427d8f380e119673b644739f736b4598b5276
7
- data.tar.gz: ad7bbd0268373292a291935599749dc9937784438b398958acf592db4e1648967106f45c1dd402c82f3cdd534f2fe0e177a1250e91f65872fc3aa9d9a8b416a5
6
+ metadata.gz: 7d45a0c77011c0bdfd4bdee3998eef649129cb51d2c248b733a35b9c2c19bb8678b2b41035afcc95f69f02e37df550bd90ef5c57a03225789de34ff7dfb65c11
7
+ data.tar.gz: dd2673d5e862524a8fad13f8ce55857d9ec3c7daed215542b9806491c428e778ce011b77c26f2dc3aa6ba24a60bfd5d1bdf9ed6cc59a702ac4daa23725fa9dce
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [2.6.2] - 2024-04-12
2
+
3
+ - Get default value for element/attribute "form" property from schema
4
+
5
+ ## [2.6.1] - 2024-04-12
6
+
7
+ - Correctly detect namespace for referenced elements
8
+
1
9
  ## [2.6.0] - 2024-04-12
2
10
 
3
11
  - Fix XSD boolean attributes
@@ -304,20 +304,24 @@ module XSD
304
304
  # check for property first
305
305
  if (property = self.class.properties[method])
306
306
  value = property[:resolve] ? property[:resolve].call(self) : node[property[:name].to_s]
307
- result = if value.nil?
308
- # if object has reference - search property in referenced object
309
- node['ref'] ? reference.send(method, *args) : property[:default]
310
- else
311
- case property[:type]
312
- when :integer
313
- property[:name] == :maxOccurs && value == 'unbounded' ? :unbounded : value.to_i
314
- when :boolean
315
- value == 'true'
316
- else
317
- value
318
- end
319
- end
320
- return @cache[method] = result
307
+ r = if value.nil?
308
+ if node['ref']
309
+ # if object has reference - search property in referenced object
310
+ reference.send(method, *args)
311
+ else
312
+ property[:default].is_a?(Proc) ? instance_eval(&property[:default]) : property[:default]
313
+ end
314
+ else
315
+ case property[:type]
316
+ when :integer
317
+ property[:name] == :maxOccurs && value == 'unbounded' ? :unbounded : value.to_i
318
+ when :boolean
319
+ value == 'true'
320
+ else
321
+ value
322
+ end
323
+ end
324
+ return @cache[method] = r
321
325
  end
322
326
 
323
327
  # if object has ref it cannot contain any type and children, so proxy call to target object
@@ -375,20 +379,19 @@ module XSD
375
379
  private
376
380
 
377
381
  def definition_match?(definition, query)
378
- actual_definition = definition.referenced? ? definition.reference : definition
379
-
382
+ # namespace included in query
380
383
  if query.start_with?('{')
381
384
  parts = query[1..].split('}')
382
385
  raise Error, "Invalid element/attribute query: #{query}" if parts.size != 2
383
386
 
384
387
  namespace, name = parts
385
388
 
386
- return false if namespace != actual_definition.namespace
389
+ return false if namespace != definition.namespace
387
390
  else
388
391
  name = query
389
392
  end
390
393
 
391
- name == '*' || actual_definition.name == name
394
+ name == '*' || definition.name == name
392
395
  end
393
396
  end
394
397
  end
@@ -28,15 +28,14 @@ module XSD
28
28
  property :fixed, :string
29
29
 
30
30
  # Optional. Specifies the form for the attribute. The default value is the value of the attributeFormDefault
31
- # attribute of the element containing the attribute. Can be set to one of the following:
31
+ # attribute of the schema containing the attribute. Can be set to one of the following:
32
32
  # qualified - indicates that this attribute must be qualified with the namespace prefix and the no-colon-name
33
33
  # (NCName) of the attribute
34
34
  # unqualified - indicates that this attribute is not required to be qualified with the namespace prefix and is
35
35
  # matched against the (NCName) of the attribute
36
36
  # @!attribute form
37
- # @return String, nil
38
- # TODO: support default value from parent
39
- property :form, :string
37
+ # @return String
38
+ property :form, :string, default: proc { schema.attribute_form_default }
40
39
 
41
40
  # Optional. Specifies a built-in data type or a simple type. The type attribute can only be present when the
42
41
  # content does not contain a simpleType element
@@ -47,7 +47,7 @@ module XSD
47
47
  # cannot be used if the parent element is the schema element
48
48
  # @!attribute form
49
49
  # @return String
50
- property :form, :string
50
+ property :form, :string, default: proc { schema.element_form_default }
51
51
 
52
52
  # Optional. Specifies whether an explicit null value can be assigned to the element. True enables an instance of
53
53
  # the element to have the null attribute set to true. The null attribute is defined as part of the XML Schema
@@ -8,8 +8,9 @@ module XSD
8
8
  class Group < BaseObject
9
9
  include MinMaxOccurs
10
10
  include Referenced
11
+ include Named
11
12
 
12
- # Optional. Specifies the name of the attribute. Name and ref attributes cannot both be present
13
+ # Optional. Specifies a name for the group. This attribute is used only when the schema element is the parent of this group element. Name and ref attributes cannot both be present
13
14
  # @!attribute name
14
15
  # @return String
15
16
  property :name, :string
@@ -5,7 +5,8 @@ module XSD
5
5
  # Get definition namespace
6
6
  # @return String
7
7
  def namespace
8
- schema.target_namespace
8
+ is_referenced = respond_to?(:referenced?)
9
+ is_referenced && referenced? ? reference.schema.target_namespace : schema.target_namespace
9
10
  end
10
11
 
11
12
  # Get absolute definition name
data/lib/xsd/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module XSD
4
- VERSION = '2.6.0'
4
+ VERSION = '2.6.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xsd
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - d.arkhipov