shale 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.md +105 -14
  4. data/exe/shaleb +79 -31
  5. data/lib/shale/attribute.rb +6 -0
  6. data/lib/shale/error.rb +6 -0
  7. data/lib/shale/mapper.rb +6 -4
  8. data/lib/shale/schema/json_compiler/boolean.rb +21 -0
  9. data/lib/shale/schema/json_compiler/date.rb +21 -0
  10. data/lib/shale/schema/json_compiler/float.rb +21 -0
  11. data/lib/shale/schema/json_compiler/integer.rb +21 -0
  12. data/lib/shale/schema/json_compiler/object.rb +85 -0
  13. data/lib/shale/schema/json_compiler/property.rb +70 -0
  14. data/lib/shale/schema/json_compiler/string.rb +21 -0
  15. data/lib/shale/schema/json_compiler/time.rb +21 -0
  16. data/lib/shale/schema/json_compiler/utils.rb +52 -0
  17. data/lib/shale/schema/json_compiler/value.rb +13 -0
  18. data/lib/shale/schema/json_compiler.rb +333 -0
  19. data/lib/shale/schema/{json → json_generator}/base.rb +2 -2
  20. data/lib/shale/schema/{json → json_generator}/boolean.rb +1 -1
  21. data/lib/shale/schema/{json → json_generator}/collection.rb +2 -2
  22. data/lib/shale/schema/{json → json_generator}/date.rb +1 -1
  23. data/lib/shale/schema/{json → json_generator}/float.rb +1 -1
  24. data/lib/shale/schema/{json → json_generator}/integer.rb +1 -1
  25. data/lib/shale/schema/{json → json_generator}/object.rb +5 -2
  26. data/lib/shale/schema/{json → json_generator}/ref.rb +1 -1
  27. data/lib/shale/schema/{json → json_generator}/schema.rb +6 -4
  28. data/lib/shale/schema/{json → json_generator}/string.rb +1 -1
  29. data/lib/shale/schema/{json → json_generator}/time.rb +1 -1
  30. data/lib/shale/schema/json_generator/value.rb +23 -0
  31. data/lib/shale/schema/{json.rb → json_generator.rb} +36 -36
  32. data/lib/shale/schema/{xml → xml_generator}/attribute.rb +1 -1
  33. data/lib/shale/schema/{xml → xml_generator}/complex_type.rb +5 -2
  34. data/lib/shale/schema/{xml → xml_generator}/element.rb +1 -1
  35. data/lib/shale/schema/{xml → xml_generator}/import.rb +1 -1
  36. data/lib/shale/schema/{xml → xml_generator}/ref_attribute.rb +1 -1
  37. data/lib/shale/schema/{xml → xml_generator}/ref_element.rb +1 -1
  38. data/lib/shale/schema/{xml → xml_generator}/schema.rb +5 -5
  39. data/lib/shale/schema/{xml → xml_generator}/typed_attribute.rb +1 -1
  40. data/lib/shale/schema/{xml → xml_generator}/typed_element.rb +1 -1
  41. data/lib/shale/schema/{xml.rb → xml_generator.rb} +22 -23
  42. data/lib/shale/schema.rb +28 -5
  43. data/lib/shale/type/composite.rb +14 -20
  44. data/lib/shale/version.rb +1 -1
  45. metadata +36 -24
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module Shale
6
+ module Schema
7
+ class JSONGenerator
8
+ # Class representing JSON Schema any type
9
+ #
10
+ # @api private
11
+ class Value < Base
12
+ # Return JSON Schema fragment as Ruby Hash
13
+ #
14
+ # @return [Hash]
15
+ #
16
+ # @api private
17
+ def as_type
18
+ { 'type' => %w[boolean integer number object string] }
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,32 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../../shale'
4
- require_relative 'json/schema'
5
- require_relative 'json/boolean'
6
- require_relative 'json/collection'
7
- require_relative 'json/date'
8
- require_relative 'json/float'
9
- require_relative 'json/integer'
10
- require_relative 'json/object'
11
- require_relative 'json/ref'
12
- require_relative 'json/string'
13
- require_relative 'json/time'
4
+ require_relative 'json_generator/schema'
5
+ require_relative 'json_generator/boolean'
6
+ require_relative 'json_generator/collection'
7
+ require_relative 'json_generator/date'
8
+ require_relative 'json_generator/float'
9
+ require_relative 'json_generator/integer'
10
+ require_relative 'json_generator/object'
11
+ require_relative 'json_generator/ref'
12
+ require_relative 'json_generator/string'
13
+ require_relative 'json_generator/time'
14
+ require_relative 'json_generator/value'
14
15
 
15
16
  module Shale
16
17
  module Schema
17
- # Class for handling JSON schema
18
+ # Class for generating JSON schema
18
19
  #
19
20
  # @api public
20
- class JSON
21
- @json_types = Hash.new(Shale::Schema::JSON::String)
21
+ class JSONGenerator
22
+ @json_types = Hash.new(Shale::Schema::JSONGenerator::String)
22
23
 
23
24
  # Register Shale to JSON type mapping
24
25
  #
25
26
  # @param [Shale::Type::Value] shale_type
26
- # @param [Shale::Schema::JSON::Base] json_type
27
+ # @param [Shale::Schema::JSONGenerator::Base] json_type
27
28
  #
28
29
  # @example
29
- # Shale::Schema::JSON.register_json_type(Shale::Type::String, MyCustomJsonType)
30
+ # Shale::Schema::JSONGenerator.register_json_type(Shale::Type::String, MyCustomJsonType)
30
31
  #
31
32
  # @api public
32
33
  def self.register_json_type(shale_type, json_type)
@@ -37,10 +38,10 @@ module Shale
37
38
  #
38
39
  # @param [Shale::Type::Value] shale_type
39
40
  #
40
- # @return [Shale::Schema::JSON::Base]
41
+ # @return [Shale::Schema::JSONGenerator::Base]
41
42
  #
42
43
  # @example
43
- # Shale::Schema::JSON.get_json_type(Shale::Type::String)
44
+ # Shale::Schema::JSONGenerator.get_json_type(Shale::Type::String)
44
45
  # # => Shale::Schema::JSON::String
45
46
  #
46
47
  # @api private
@@ -48,11 +49,12 @@ module Shale
48
49
  @json_types[shale_type]
49
50
  end
50
51
 
51
- register_json_type(Shale::Type::Boolean, Shale::Schema::JSON::Boolean)
52
- register_json_type(Shale::Type::Date, Shale::Schema::JSON::Date)
53
- register_json_type(Shale::Type::Float, Shale::Schema::JSON::Float)
54
- register_json_type(Shale::Type::Integer, Shale::Schema::JSON::Integer)
55
- register_json_type(Shale::Type::Time, Shale::Schema::JSON::Time)
52
+ register_json_type(Shale::Type::Boolean, Shale::Schema::JSONGenerator::Boolean)
53
+ register_json_type(Shale::Type::Date, Shale::Schema::JSONGenerator::Date)
54
+ register_json_type(Shale::Type::Float, Shale::Schema::JSONGenerator::Float)
55
+ register_json_type(Shale::Type::Integer, Shale::Schema::JSONGenerator::Integer)
56
+ register_json_type(Shale::Type::Time, Shale::Schema::JSONGenerator::Time)
57
+ register_json_type(Shale::Type::Value, Shale::Schema::JSONGenerator::Value)
56
58
 
57
59
  # Generate JSON Schema from Shale model and return it as a Ruby Hash
58
60
  #
@@ -65,15 +67,16 @@ module Shale
65
67
  # @return [Hash]
66
68
  #
67
69
  # @example
68
- # Shale::Schema::JSON.new.as_schema(Person)
70
+ # Shale::Schema::JSONGenerator.new.as_schema(Person)
69
71
  #
70
72
  # @api public
71
- def as_schema(klass, id: nil, description: nil)
73
+ def as_schema(klass, id: nil, title: nil, description: nil)
72
74
  unless mapper_type?(klass)
73
75
  raise NotAShaleMapperError, "JSON Shema can't be generated for '#{klass}' type"
74
76
  end
75
77
 
76
- types = collect_composite_types(klass)
78
+ types = []
79
+ collect_composite_types(types, klass)
77
80
  objects = []
78
81
 
79
82
  types.each do |type|
@@ -103,7 +106,7 @@ module Shale
103
106
  objects << Object.new(type.name, properties)
104
107
  end
105
108
 
106
- Schema.new(objects, id: id, description: description).as_json
109
+ Schema.new(objects, id: id, title: title, description: description).as_json
107
110
  end
108
111
 
109
112
  # Generate JSON Schema from Shale model
@@ -116,11 +119,11 @@ module Shale
116
119
  # @return [String]
117
120
  #
118
121
  # @example
119
- # Shale::Schema::JSON.new.to_schema(Person)
122
+ # Shale::Schema::JSONGenerator.new.to_schema(Person)
120
123
  #
121
124
  # @api public
122
- def to_schema(klass, id: nil, description: nil, pretty: false)
123
- schema = as_schema(klass, id: id, description: description)
125
+ def to_schema(klass, id: nil, title: nil, description: nil, pretty: false)
126
+ schema = as_schema(klass, id: id, title: title, description: description)
124
127
  options = pretty ? :pretty : nil
125
128
 
126
129
  Shale.json_adapter.dump(schema, options)
@@ -141,24 +144,21 @@ module Shale
141
144
 
142
145
  # Collect recursively Shale::Mapper types
143
146
  #
147
+ # @param [Array<Shale::Mapper>] types
144
148
  # @param [Shale::Mapper] type
145
149
  #
146
- # @return [Array<Shale::Mapper>]
147
- #
148
150
  # @api private
149
- def collect_composite_types(type)
150
- types = [type]
151
+ def collect_composite_types(types, type)
152
+ types << type
151
153
 
152
154
  type.json_mapping.keys.values.each do |mapping|
153
155
  attribute = type.attributes[mapping.attribute]
154
156
  next unless attribute
155
157
 
156
158
  if mapper_type?(attribute.type) && !types.include?(attribute.type)
157
- types += collect_composite_types(attribute.type)
159
+ collect_composite_types(types, attribute.type)
158
160
  end
159
161
  end
160
-
161
- types.uniq
162
162
  end
163
163
  end
164
164
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Shale
4
4
  module Schema
5
- class XML
5
+ class XMLGenerator
6
6
  # Class representing XML Schema <attribute> element.
7
7
  # Serves as a base class for TypedAttribute and RefAttribute
8
8
  #
@@ -5,7 +5,7 @@ require_relative 'element'
5
5
 
6
6
  module Shale
7
7
  module Schema
8
- class XML
8
+ class XMLGenerator
9
9
  # Class representing XML Schema <complexType> element
10
10
  #
11
11
  # @api private
@@ -20,7 +20,10 @@ module Shale
20
20
  # Initialize ComplexType object
21
21
  #
22
22
  # @param [String] name
23
- # @param [Array<Shale::Schema::XML::Element, Shale::Schema::XML::Attribute>] children
23
+ # @param [Array<
24
+ # Shale::Schema::XMLGenerator::Element,
25
+ # Shale::Schema::XMLGenerator::Attribute
26
+ # >] children
24
27
  # @param [true, false] mixed
25
28
  #
26
29
  # @api private
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Shale
4
4
  module Schema
5
- class XML
5
+ class XMLGenerator
6
6
  # Class representing XML Schema <element> element.
7
7
  # Serves as a base class for TypedElement and RefElement
8
8
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Shale
4
4
  module Schema
5
- class XML
5
+ class XMLGenerator
6
6
  # Class representing XML Schema <import> element
7
7
  #
8
8
  # @api private
@@ -4,7 +4,7 @@ require_relative 'attribute'
4
4
 
5
5
  module Shale
6
6
  module Schema
7
- class XML
7
+ class XMLGenerator
8
8
  # Class representing XML Schema <attribute ref=""> element
9
9
  # with a reference
10
10
  #
@@ -4,7 +4,7 @@ require_relative 'element'
4
4
 
5
5
  module Shale
6
6
  module Schema
7
- class XML
7
+ class XMLGenerator
8
8
  # Class representing XML Schema <element ref=""> element
9
9
  # with a reference
10
10
  #
@@ -5,7 +5,7 @@ require_relative 'complex_type'
5
5
 
6
6
  module Shale
7
7
  module Schema
8
- class XML
8
+ class XMLGenerator
9
9
  class Schema
10
10
  # XML Schema namespace
11
11
  # @api private
@@ -43,10 +43,10 @@ module Shale
43
43
 
44
44
  # Add child element to XML Schema
45
45
  #
46
- # @param [Shale::Schema::XML::Import,
47
- # Shale::Schema::XML::Element,
48
- # Shale::Schema::XML::Attribute,
49
- # Shale::Schema::XML::ComplesType] child
46
+ # @param [Shale::Schema::XMLGenerator::Import,
47
+ # Shale::Schema::XMLGenerator::Element,
48
+ # Shale::Schema::XMLGenerator::Attribute,
49
+ # Shale::Schema::XMLGenerator::ComplesType] child
50
50
  #
51
51
  # @api private
52
52
  def add_child(child)
@@ -4,7 +4,7 @@ require_relative 'attribute'
4
4
 
5
5
  module Shale
6
6
  module Schema
7
- class XML
7
+ class XMLGenerator
8
8
  # Class representing XML Schema <attribute name="" type=""> element
9
9
  # with a name and a type
10
10
  #
@@ -4,7 +4,7 @@ require_relative 'element'
4
4
 
5
5
  module Shale
6
6
  module Schema
7
- class XML
7
+ class XMLGenerator
8
8
  # Class representing XML Schema <element mame="" type=""> element
9
9
  # with a name and a type
10
10
  #
@@ -1,20 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../../shale'
4
- require_relative 'xml/complex_type'
5
- require_relative 'xml/import'
6
- require_relative 'xml/ref_attribute'
7
- require_relative 'xml/ref_element'
8
- require_relative 'xml/schema'
9
- require_relative 'xml/typed_attribute'
10
- require_relative 'xml/typed_element'
4
+ require_relative 'xml_generator/complex_type'
5
+ require_relative 'xml_generator/import'
6
+ require_relative 'xml_generator/ref_attribute'
7
+ require_relative 'xml_generator/ref_element'
8
+ require_relative 'xml_generator/schema'
9
+ require_relative 'xml_generator/typed_attribute'
10
+ require_relative 'xml_generator/typed_element'
11
11
 
12
12
  module Shale
13
13
  module Schema
14
- # Class for handling XML schema
14
+ # Class for generating XML schema
15
15
  #
16
16
  # @api public
17
- class XML
17
+ class XMLGenerator
18
18
  # XML Schema default name
19
19
  # @api private
20
20
  DEFAULT_SCHEMA_NAME = 'schema'
@@ -27,7 +27,7 @@ module Shale
27
27
  # @param [String] xml_type
28
28
  #
29
29
  # @example
30
- # Shale::Schema::XML.register_xml_type(Shale::Type::String, 'myType')
30
+ # Shale::Schema::XMLGenerator.register_xml_type(Shale::Type::String, 'myType')
31
31
  #
32
32
  # @api public
33
33
  def self.register_xml_type(shale_type, xml_type)
@@ -41,7 +41,7 @@ module Shale
41
41
  # @return [String]
42
42
  #
43
43
  # @example
44
- # Shale::Schema::XML.get_xml_type(Shale::Type::String)
44
+ # Shale::Schema::XMLGenerator.get_xml_type(Shale::Type::String)
45
45
  # # => 'string'
46
46
  #
47
47
  # @api private
@@ -54,19 +54,20 @@ module Shale
54
54
  register_xml_type(Shale::Type::Float, 'decimal')
55
55
  register_xml_type(Shale::Type::Integer, 'integer')
56
56
  register_xml_type(Shale::Type::Time, 'dateTime')
57
+ register_xml_type(Shale::Type::Value, 'anyType')
57
58
 
58
59
  # Generate XML Schema from Shale model and return
59
- # it as a Shale::Schema::XML::Schema array
60
+ # it as a Shale::Schema::XMLGenerator::Schema array
60
61
  #
61
62
  # @param [Shale::Mapper] klass
62
63
  # @param [String, nil] base_name
63
64
  #
64
65
  # @raise [NotAShaleMapperError] when attribute is not a Shale model
65
66
  #
66
- # @return [Array<Shale::Schema::XML::Schema>]
67
+ # @return [Array<Shale::Schema::XMLGenerator::Schema>]
67
68
  #
68
69
  # @example
69
- # Shale::Schema::XML.new.as_schemas(Person)
70
+ # Shale::Schema::XMLGenerator.new.as_schemas(Person)
70
71
  #
71
72
  # @api public
72
73
  def as_schemas(klass, base_name = nil)
@@ -93,7 +94,8 @@ module Shale
93
94
  )
94
95
  schemas[default_namespace.name].add_child(root_element)
95
96
 
96
- composites = collect_composite_types(klass, klass.xml_mapping.default_namespace.name)
97
+ composites = []
98
+ collect_composite_types(composites, klass, klass.xml_mapping.default_namespace.name)
97
99
 
98
100
  composites.each do |composite|
99
101
  type = composite[:type]
@@ -214,7 +216,7 @@ module Shale
214
216
  # @return [Hash<String, String>]
215
217
  #
216
218
  # @example
217
- # Shale::Schema::XML.new.to_schemas(Person)
219
+ # Shale::Schema::XMLGenerator.new.to_schemas(Person)
218
220
  #
219
221
  # @api public
220
222
  def to_schemas(klass, base_name = nil, pretty: false, declaration: false)
@@ -245,14 +247,13 @@ module Shale
245
247
 
246
248
  # Collect recursively Shale::Mapper types
247
249
  #
250
+ # @param [Array<Shale::Mapper>] types
248
251
  # @param [Shale::Mapper] type
249
252
  # @param [String, nil] namespace
250
253
  #
251
- # @return [Array<Hash<Symbol, String>>]
252
- #
253
254
  # @api private
254
- def collect_composite_types(type, namespace)
255
- types = [{ type: type, namespace: namespace }]
255
+ def collect_composite_types(types, type, namespace)
256
+ types << { type: type, namespace: namespace }
256
257
 
257
258
  type.xml_mapping.elements.values.each do |mapping|
258
259
  attribute = type.attributes[mapping.attribute]
@@ -262,11 +263,9 @@ module Shale
262
263
  is_included = types.include?({ type: attribute.type, namespace: namespace })
263
264
 
264
265
  if is_mapper && !is_included
265
- types += collect_composite_types(attribute.type, mapping.namespace.name)
266
+ collect_composite_types(types, attribute.type, mapping.namespace.name)
266
267
  end
267
268
  end
268
-
269
- types.uniq
270
269
  end
271
270
 
272
271
  # Convert Ruby class name to XML Schema name
data/lib/shale/schema.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'schema/json'
4
- require_relative 'schema/xml'
3
+ require_relative 'schema/json_generator'
4
+ require_relative 'schema/json_compiler'
5
+ require_relative 'schema/xml_generator'
5
6
 
6
7
  module Shale
7
8
  # Module for handling JSON and XML schema
@@ -22,8 +23,30 @@ module Shale
22
23
  # # => JSON schema
23
24
  #
24
25
  # @api public
25
- def self.to_json(klass, id: nil, description: nil, pretty: false)
26
- JSON.new.to_schema(klass, id: id, description: description, pretty: pretty)
26
+ def self.to_json(klass, id: nil, title: nil, description: nil, pretty: false)
27
+ JSONGenerator.new.to_schema(
28
+ klass,
29
+ id: id,
30
+ title: title,
31
+ description: description,
32
+ pretty: pretty
33
+ )
34
+ end
35
+
36
+ # Generate Shale model from JSON Schema
37
+ #
38
+ # @param [Array<String>] schemas
39
+ # @param [String, nil] root_name
40
+ #
41
+ # @return [Array<String>]
42
+ #
43
+ # @example
44
+ # Shale::Schema.from_json([json_schema1, json_schema2], root_name: 'foobar')
45
+ # # => [model1, model2, model3]
46
+ #
47
+ # @api public
48
+ def self.from_json(schemas, root_name: nil)
49
+ JSONCompiler.new.to_models(schemas, root_name: root_name)
27
50
  end
28
51
 
29
52
  # Generate XML Schema from Shale model
@@ -41,7 +64,7 @@ module Shale
41
64
  #
42
65
  # @api public
43
66
  def self.to_xml(klass, base_name = nil, pretty: false, declaration: false)
44
- XML.new.to_schemas(klass, base_name, pretty: pretty, declaration: declaration)
67
+ XMLGenerator.new.to_schemas(klass, base_name, pretty: pretty, declaration: declaration)
45
68
  end
46
69
  end
47
70
  end
@@ -35,18 +35,15 @@ module Shale
35
35
  next unless attribute
36
36
 
37
37
  if value.nil?
38
- instance.public_send("\#{attribute.name}=", nil)
39
- next
40
- end
41
-
42
- if attribute.collection?
38
+ instance.send(attribute.setter, nil)
39
+ elsif attribute.collection?
43
40
  [*value].each do |val|
44
41
  val = val ? attribute.type.of_#{format}(val) : val
45
- instance.public_send(attribute.name) << attribute.type.cast(val)
42
+ instance.send(attribute.name) << attribute.type.cast(val)
46
43
  end
47
44
  else
48
45
  val = attribute.type.of_#{format}(value)
49
- instance.public_send("\#{attribute.name}=", val)
46
+ instance.send(attribute.setter, val)
50
47
  end
51
48
  end
52
49
  end
@@ -71,14 +68,11 @@ module Shale
71
68
  attribute = instance.class.attributes[mapping.attribute]
72
69
  next unless attribute
73
70
 
74
- value = instance.public_send(attribute.name)
71
+ value = instance.send(attribute.name)
75
72
 
76
73
  if value.nil?
77
74
  hash[mapping.name] = nil
78
- next
79
- end
80
-
81
- if attribute.collection?
75
+ elsif attribute.collection?
82
76
  hash[mapping.name] = [*value].map do |v|
83
77
  v ? attribute.type.as_#{format}(v) : v
84
78
  end
@@ -163,9 +157,9 @@ module Shale
163
157
  next unless attribute
164
158
 
165
159
  if attribute.collection?
166
- instance.public_send(attribute.name) << attribute.type.cast(value)
160
+ instance.send(attribute.name) << attribute.type.cast(value)
167
161
  else
168
- instance.public_send("#{attribute.name}=", value)
162
+ instance.send(attribute.setter, value)
169
163
  end
170
164
  end
171
165
  end
@@ -174,7 +168,7 @@ module Shale
174
168
  attribute = attributes[xml_mapping.content]
175
169
 
176
170
  if attribute
177
- instance.public_send("#{attribute.name}=", attribute.type.of_xml(element))
171
+ instance.send(attribute.setter, attribute.type.of_xml(element))
178
172
  end
179
173
  end
180
174
 
@@ -190,9 +184,9 @@ module Shale
190
184
 
191
185
  if attribute.collection?
192
186
  value = attribute.type.of_xml(node)
193
- instance.public_send(attribute.name) << attribute.type.cast(value)
187
+ instance.send(attribute.name) << attribute.type.cast(value)
194
188
  else
195
- instance.public_send("#{attribute.name}=", attribute.type.of_xml(node))
189
+ instance.send(attribute.setter, attribute.type.of_xml(node))
196
190
  end
197
191
  end
198
192
  end
@@ -237,7 +231,7 @@ module Shale
237
231
  attribute = instance.class.attributes[mapping.attribute]
238
232
  next unless attribute
239
233
 
240
- value = instance.public_send(attribute.name)
234
+ value = instance.send(attribute.name)
241
235
  next if value.nil?
242
236
 
243
237
  doc.add_namespace(mapping.namespace.prefix, mapping.namespace.name)
@@ -249,7 +243,7 @@ module Shale
249
243
  attribute = instance.class.attributes[xml_mapping.content]
250
244
 
251
245
  if attribute
252
- value = instance.public_send(attribute.name)
246
+ value = instance.send(attribute.name)
253
247
  doc.add_text(element, value.to_s) if value
254
248
  end
255
249
  end
@@ -261,7 +255,7 @@ module Shale
261
255
  attribute = instance.class.attributes[mapping.attribute]
262
256
  next unless attribute
263
257
 
264
- value = instance.public_send(attribute.name)
258
+ value = instance.send(attribute.name)
265
259
  next if value.nil?
266
260
 
267
261
  doc.add_namespace(mapping.namespace.prefix, mapping.namespace.name)
data/lib/shale/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Shale
4
4
  # @api private
5
- VERSION = '0.3.1'
5
+ VERSION = '0.4.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kamil Giszczak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-10 00:00:00.000000000 Z
11
+ date: 2022-05-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby object mapper and serializer for XML, JSON and YAML.
14
14
  email:
@@ -37,28 +37,40 @@ files:
37
37
  - lib/shale/mapping/validator.rb
38
38
  - lib/shale/mapping/xml.rb
39
39
  - lib/shale/schema.rb
40
- - lib/shale/schema/json.rb
41
- - lib/shale/schema/json/base.rb
42
- - lib/shale/schema/json/boolean.rb
43
- - lib/shale/schema/json/collection.rb
44
- - lib/shale/schema/json/date.rb
45
- - lib/shale/schema/json/float.rb
46
- - lib/shale/schema/json/integer.rb
47
- - lib/shale/schema/json/object.rb
48
- - lib/shale/schema/json/ref.rb
49
- - lib/shale/schema/json/schema.rb
50
- - lib/shale/schema/json/string.rb
51
- - lib/shale/schema/json/time.rb
52
- - lib/shale/schema/xml.rb
53
- - lib/shale/schema/xml/attribute.rb
54
- - lib/shale/schema/xml/complex_type.rb
55
- - lib/shale/schema/xml/element.rb
56
- - lib/shale/schema/xml/import.rb
57
- - lib/shale/schema/xml/ref_attribute.rb
58
- - lib/shale/schema/xml/ref_element.rb
59
- - lib/shale/schema/xml/schema.rb
60
- - lib/shale/schema/xml/typed_attribute.rb
61
- - lib/shale/schema/xml/typed_element.rb
40
+ - lib/shale/schema/json_compiler.rb
41
+ - lib/shale/schema/json_compiler/boolean.rb
42
+ - lib/shale/schema/json_compiler/date.rb
43
+ - lib/shale/schema/json_compiler/float.rb
44
+ - lib/shale/schema/json_compiler/integer.rb
45
+ - lib/shale/schema/json_compiler/object.rb
46
+ - lib/shale/schema/json_compiler/property.rb
47
+ - lib/shale/schema/json_compiler/string.rb
48
+ - lib/shale/schema/json_compiler/time.rb
49
+ - lib/shale/schema/json_compiler/utils.rb
50
+ - lib/shale/schema/json_compiler/value.rb
51
+ - lib/shale/schema/json_generator.rb
52
+ - lib/shale/schema/json_generator/base.rb
53
+ - lib/shale/schema/json_generator/boolean.rb
54
+ - lib/shale/schema/json_generator/collection.rb
55
+ - lib/shale/schema/json_generator/date.rb
56
+ - lib/shale/schema/json_generator/float.rb
57
+ - lib/shale/schema/json_generator/integer.rb
58
+ - lib/shale/schema/json_generator/object.rb
59
+ - lib/shale/schema/json_generator/ref.rb
60
+ - lib/shale/schema/json_generator/schema.rb
61
+ - lib/shale/schema/json_generator/string.rb
62
+ - lib/shale/schema/json_generator/time.rb
63
+ - lib/shale/schema/json_generator/value.rb
64
+ - lib/shale/schema/xml_generator.rb
65
+ - lib/shale/schema/xml_generator/attribute.rb
66
+ - lib/shale/schema/xml_generator/complex_type.rb
67
+ - lib/shale/schema/xml_generator/element.rb
68
+ - lib/shale/schema/xml_generator/import.rb
69
+ - lib/shale/schema/xml_generator/ref_attribute.rb
70
+ - lib/shale/schema/xml_generator/ref_element.rb
71
+ - lib/shale/schema/xml_generator/schema.rb
72
+ - lib/shale/schema/xml_generator/typed_attribute.rb
73
+ - lib/shale/schema/xml_generator/typed_element.rb
62
74
  - lib/shale/type/boolean.rb
63
75
  - lib/shale/type/composite.rb
64
76
  - lib/shale/type/date.rb