schematic 0.0.5 → 0.0.6
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.
- data/.rvmrc +1 -1
- data/lib/schematic/serializers/xsd.rb +8 -2
- data/lib/schematic/version.rb +1 -1
- data/spec/schematic_serializers_xsd_spec.rb +103 -11
- metadata +2 -2
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm 1.9.2-p136@schematic
|
1
|
+
rvm 1.9.2-p136@schematic --create
|
@@ -115,8 +115,14 @@ module Schematic
|
|
115
115
|
builder.xs :element, "name" => method_xsd_name, "minOccurs" => "0", "maxOccurs" => "1" do |element|
|
116
116
|
element.xs :complexType do |complex_type|
|
117
117
|
complex_type.xs :all do |nested_all|
|
118
|
-
values.
|
119
|
-
|
118
|
+
if values.is_a?(Array)
|
119
|
+
values.each do |value|
|
120
|
+
nested_all.xs :element, "name" => value.to_s.dasherize, "minOccurs" => "0"
|
121
|
+
end
|
122
|
+
elsif values.is_a?(Hash)
|
123
|
+
generate_xsd_additional_methods(nested_all, values)
|
124
|
+
else
|
125
|
+
raise "Additional methods must be a hash of hashes or hash of arrays"
|
120
126
|
end
|
121
127
|
end
|
122
128
|
complex_type.xs :attribute, "name" => "type", "type" => "xs:string", "fixed" => "array", "use" => "optional"
|
data/lib/schematic/version.rb
CHANGED
@@ -55,6 +55,12 @@ describe Schematic::Serializers::Xsd do
|
|
55
55
|
validates :some_string, :presence => true
|
56
56
|
validates :some_date, :presence => true, :allow_blank => true
|
57
57
|
validates :some_datetime, :presence => true, :allow_blank => false
|
58
|
+
|
59
|
+
class << self
|
60
|
+
def xsd_methods
|
61
|
+
{:foo => { :bar => { :baz => nil } } }
|
62
|
+
end
|
63
|
+
end
|
58
64
|
end
|
59
65
|
|
60
66
|
end
|
@@ -347,19 +353,20 @@ describe Schematic::Serializers::Xsd do
|
|
347
353
|
end
|
348
354
|
|
349
355
|
describe ".xsd_methods" do
|
350
|
-
|
351
|
-
|
356
|
+
context "given a method" do
|
357
|
+
with_model :some_model do
|
358
|
+
table {}
|
352
359
|
|
353
|
-
|
354
|
-
|
355
|
-
|
360
|
+
model do
|
361
|
+
def self.xsd_methods
|
362
|
+
{:foo_bar => nil}
|
363
|
+
end
|
356
364
|
end
|
357
365
|
end
|
358
|
-
end
|
359
366
|
|
360
|
-
|
361
|
-
|
362
|
-
|
367
|
+
it "should include the additional method" do
|
368
|
+
xsd = generate_xsd_for_model(SomeModel) do
|
369
|
+
<<-XML
|
363
370
|
<xs:element name="id" minOccurs="0" maxOccurs="1">
|
364
371
|
<xs:complexType>
|
365
372
|
<xs:simpleContent>
|
@@ -370,10 +377,95 @@ describe Schematic::Serializers::Xsd do
|
|
370
377
|
</xs:complexType>
|
371
378
|
</xs:element>
|
372
379
|
<xs:element name="foo-bar" minOccurs="0" maxOccurs="1"/>
|
373
|
-
|
380
|
+
XML
|
381
|
+
end
|
382
|
+
|
383
|
+
SomeModel.to_xsd.should == sanitize_xml(xsd)
|
374
384
|
end
|
385
|
+
end
|
375
386
|
|
376
|
-
|
387
|
+
context "given a an array of methods" do
|
388
|
+
with_model :some_model do
|
389
|
+
table {}
|
390
|
+
|
391
|
+
model do
|
392
|
+
def self.xsd_methods
|
393
|
+
{:foo => [:bar, :baz]}
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
it "should include the additional methods" do
|
399
|
+
xsd = generate_xsd_for_model(SomeModel) do
|
400
|
+
<<-XML
|
401
|
+
<xs:element name="id" minOccurs="0" maxOccurs="1">
|
402
|
+
<xs:complexType>
|
403
|
+
<xs:simpleContent>
|
404
|
+
<xs:extension base="xs:integer">
|
405
|
+
<xs:attribute name="type" type="xs:string" use="optional"/>
|
406
|
+
</xs:extension>
|
407
|
+
</xs:simpleContent>
|
408
|
+
</xs:complexType>
|
409
|
+
</xs:element>
|
410
|
+
<xs:element name="foo" minOccurs="0" maxOccurs="1">
|
411
|
+
<xs:complexType>
|
412
|
+
<xs:all>
|
413
|
+
<xs:element name="bar" minOccurs="0"/>
|
414
|
+
<xs:element name="baz" minOccurs="0"/>
|
415
|
+
</xs:all>
|
416
|
+
<xs:attribute name="type" type="xs:string" fixed="array" use="optional"/>
|
417
|
+
</xs:complexType>
|
418
|
+
</xs:element>
|
419
|
+
XML
|
420
|
+
end
|
421
|
+
|
422
|
+
SomeModel.to_xsd.should == sanitize_xml(xsd)
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
context "given nested methods" do
|
427
|
+
with_model :some_model do
|
428
|
+
table {}
|
429
|
+
|
430
|
+
model do
|
431
|
+
def self.xsd_methods
|
432
|
+
{ :foo => { :bar => {:baz => nil } } }
|
433
|
+
end
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
it "should nested the additional methods" do
|
438
|
+
xsd = generate_xsd_for_model(SomeModel) do
|
439
|
+
<<-XML
|
440
|
+
<xs:element name="id" minOccurs="0" maxOccurs="1">
|
441
|
+
<xs:complexType>
|
442
|
+
<xs:simpleContent>
|
443
|
+
<xs:extension base="xs:integer">
|
444
|
+
<xs:attribute name="type" type="xs:string" use="optional"/>
|
445
|
+
</xs:extension>
|
446
|
+
</xs:simpleContent>
|
447
|
+
</xs:complexType>
|
448
|
+
</xs:element>
|
449
|
+
<xs:element name="foo" minOccurs="0" maxOccurs="1">
|
450
|
+
<xs:complexType>
|
451
|
+
<xs:all>
|
452
|
+
<xs:element name="bar" minOccurs="0" maxOccurs="1">
|
453
|
+
<xs:complexType>
|
454
|
+
<xs:all>
|
455
|
+
<xs:element name="baz" minOccurs="0" maxOccurs="1"/>
|
456
|
+
</xs:all>
|
457
|
+
<xs:attribute name="type" type="xs:string" fixed="array" use="optional"/>
|
458
|
+
</xs:complexType>
|
459
|
+
</xs:element>
|
460
|
+
</xs:all>
|
461
|
+
<xs:attribute name="type" type="xs:string" fixed="array" use="optional"/>
|
462
|
+
</xs:complexType>
|
463
|
+
</xs:element>
|
464
|
+
XML
|
465
|
+
end
|
466
|
+
|
467
|
+
SomeModel.to_xsd.should == sanitize_xml(xsd)
|
468
|
+
end
|
377
469
|
end
|
378
470
|
end
|
379
471
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: schematic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Case Commons, LLC
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-12 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|