shale 0.4.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +449 -40
  5. data/exe/shaleb +30 -6
  6. data/lib/shale/adapter/json.rb +3 -3
  7. data/lib/shale/adapter/nokogiri/document.rb +97 -0
  8. data/lib/shale/adapter/nokogiri/node.rb +100 -0
  9. data/lib/shale/adapter/nokogiri.rb +17 -156
  10. data/lib/shale/adapter/ox/document.rb +90 -0
  11. data/lib/shale/adapter/ox/node.rb +97 -0
  12. data/lib/shale/adapter/ox.rb +14 -138
  13. data/lib/shale/adapter/rexml/document.rb +98 -0
  14. data/lib/shale/adapter/rexml/node.rb +99 -0
  15. data/lib/shale/adapter/rexml.rb +14 -154
  16. data/lib/shale/adapter/toml_rb.rb +34 -0
  17. data/lib/shale/error.rb +57 -2
  18. data/lib/shale/mapper.rb +61 -9
  19. data/lib/shale/mapping/descriptor/dict.rb +12 -1
  20. data/lib/shale/mapping/descriptor/xml.rb +12 -2
  21. data/lib/shale/mapping/dict.rb +26 -2
  22. data/lib/shale/mapping/xml.rb +52 -6
  23. data/lib/shale/schema/{json_compiler → compiler}/boolean.rb +1 -1
  24. data/lib/shale/schema/{json_compiler/object.rb → compiler/complex.rb} +11 -8
  25. data/lib/shale/schema/{json_compiler → compiler}/date.rb +1 -1
  26. data/lib/shale/schema/{json_compiler → compiler}/float.rb +1 -1
  27. data/lib/shale/schema/{json_compiler → compiler}/integer.rb +1 -1
  28. data/lib/shale/schema/{json_compiler → compiler}/property.rb +6 -6
  29. data/lib/shale/schema/{json_compiler → compiler}/string.rb +1 -1
  30. data/lib/shale/schema/{json_compiler → compiler}/time.rb +1 -1
  31. data/lib/shale/schema/compiler/value.rb +21 -0
  32. data/lib/shale/schema/compiler/xml_complex.rb +50 -0
  33. data/lib/shale/schema/compiler/xml_property.rb +73 -0
  34. data/lib/shale/schema/json_compiler.rb +32 -34
  35. data/lib/shale/schema/json_generator.rb +4 -6
  36. data/lib/shale/schema/xml_compiler.rb +919 -0
  37. data/lib/shale/schema/xml_generator/import.rb +2 -2
  38. data/lib/shale/schema/xml_generator.rb +11 -13
  39. data/lib/shale/schema.rb +16 -0
  40. data/lib/shale/type/complex.rb +763 -0
  41. data/lib/shale/type/value.rb +38 -9
  42. data/lib/shale/utils.rb +42 -7
  43. data/lib/shale/version.rb +1 -1
  44. data/lib/shale.rb +22 -19
  45. data/shale.gemspec +3 -3
  46. metadata +26 -17
  47. data/lib/shale/schema/json_compiler/utils.rb +0 -52
  48. data/lib/shale/schema/json_compiler/value.rb +0 -13
  49. data/lib/shale/type/composite.rb +0 -331
@@ -35,8 +35,8 @@ module Shale
35
35
  def as_xml(doc)
36
36
  import = doc.create_element('xs:import')
37
37
 
38
- doc.add_attribute(import, 'namespace', @namespace)
39
- doc.add_attribute(import, 'schemaLocation', @location)
38
+ doc.add_attribute(import, 'namespace', @namespace) if @namespace
39
+ doc.add_attribute(import, 'schemaLocation', @location) if @location
40
40
 
41
41
  import
42
42
  end
@@ -94,12 +94,12 @@ module Shale
94
94
  )
95
95
  schemas[default_namespace.name].add_child(root_element)
96
96
 
97
- composites = []
98
- collect_composite_types(composites, klass, klass.xml_mapping.default_namespace.name)
97
+ complexes = []
98
+ collect_complex_types(complexes, klass, klass.xml_mapping.default_namespace.name)
99
99
 
100
- composites.each do |composite|
101
- type = composite[:type]
102
- namespace = composite[:namespace]
100
+ complexes.each do |complex|
101
+ type = complex[:type]
102
+ namespace = complex[:namespace]
103
103
  children = []
104
104
 
105
105
  type.xml_mapping.elements.values.each do |mapping|
@@ -222,13 +222,11 @@ module Shale
222
222
  def to_schemas(klass, base_name = nil, pretty: false, declaration: false)
223
223
  schemas = as_schemas(klass, base_name)
224
224
 
225
- options = [
226
- pretty ? :pretty : nil,
227
- declaration ? :declaration : nil,
228
- ]
229
-
230
225
  schemas.to_h do |schema|
231
- [schema.name, Shale.xml_adapter.dump(schema.as_xml, *options)]
226
+ [
227
+ schema.name,
228
+ Shale.xml_adapter.dump(schema.as_xml, pretty: pretty, declaration: declaration),
229
+ ]
232
230
  end
233
231
  end
234
232
 
@@ -252,7 +250,7 @@ module Shale
252
250
  # @param [String, nil] namespace
253
251
  #
254
252
  # @api private
255
- def collect_composite_types(types, type, namespace)
253
+ def collect_complex_types(types, type, namespace)
256
254
  types << { type: type, namespace: namespace }
257
255
 
258
256
  type.xml_mapping.elements.values.each do |mapping|
@@ -263,7 +261,7 @@ module Shale
263
261
  is_included = types.include?({ type: attribute.type, namespace: namespace })
264
262
 
265
263
  if is_mapper && !is_included
266
- collect_composite_types(types, attribute.type, mapping.namespace.name)
264
+ collect_complex_types(types, attribute.type, mapping.namespace.name)
267
265
  end
268
266
  end
269
267
  end
data/lib/shale/schema.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative 'schema/json_generator'
4
4
  require_relative 'schema/json_compiler'
5
5
  require_relative 'schema/xml_generator'
6
+ require_relative 'schema/xml_compiler'
6
7
 
7
8
  module Shale
8
9
  # Module for handling JSON and XML schema
@@ -66,5 +67,20 @@ module Shale
66
67
  def self.to_xml(klass, base_name = nil, pretty: false, declaration: false)
67
68
  XMLGenerator.new.to_schemas(klass, base_name, pretty: pretty, declaration: declaration)
68
69
  end
70
+
71
+ # Generate Shale model from XML Schema
72
+ #
73
+ # @param [Array<String>] schemas
74
+ #
75
+ # @return [Array<String>]
76
+ #
77
+ # @example
78
+ # Shale::Schema.from_xml([xml_schema1, xml_schema2])
79
+ # # => [model1, model2, model3]
80
+ #
81
+ # @api public
82
+ def self.from_xml(schemas)
83
+ XMLCompiler.new.to_models(schemas)
84
+ end
69
85
  end
70
86
  end