schematic 0.0.8 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,3 +8,103 @@ RSpec.configure do |config|
8
8
  end
9
9
 
10
10
  ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ":memory:")
11
+
12
+ def validate_xml_against_xsd(xml, xsd)
13
+ require "tempfile"
14
+ tempfile = Tempfile.new("schematic")
15
+ tempfile << xsd
16
+ tempfile.rewind
17
+ xsd = Nokogiri::XML::Schema(tempfile)
18
+ doc = Nokogiri::XML.parse(xml)
19
+ errors = []
20
+ xsd.validate(doc).each do |error|
21
+ errors << error.message
22
+ end
23
+ errors.should == []
24
+ ensure
25
+ tempfile.close
26
+ end
27
+
28
+ def validate_xsd(xml)
29
+ xsd_schema_file = File.join(File.dirname(__FILE__), "xsd", "XMLSchema.xsd")
30
+ meta_xsd = Nokogiri::XML::Schema(File.open(xsd_schema_file))
31
+
32
+ doc = Nokogiri::XML.parse(xml)
33
+ meta_xsd.validate(doc).each do |error|
34
+ error.message.should be_nil
35
+ end
36
+ end
37
+
38
+ def sanitize_xml(xml)
39
+ xml.split("\n").reject(&:blank?).map(&:strip).join("\n")
40
+ end
41
+
42
+ def generate_xsd_for_model(model)
43
+ output = <<-XML
44
+ <?xml version="1.0" encoding="UTF-8"?>
45
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
46
+ <xs:complexType name="Integer">
47
+ <xs:simpleContent>
48
+ <xs:extension base="xs:integer">
49
+ <xs:attribute name="type" type="xs:string" use="optional"/>
50
+ </xs:extension>
51
+ </xs:simpleContent>
52
+ </xs:complexType>
53
+ <xs:complexType name="Float">
54
+ <xs:simpleContent>
55
+ <xs:extension base="xs:float">
56
+ <xs:attribute name="type" type="xs:string" use="optional"/>
57
+ </xs:extension>
58
+ </xs:simpleContent>
59
+ </xs:complexType>
60
+ <xs:complexType name="String">
61
+ <xs:simpleContent>
62
+ <xs:extension base="xs:string">
63
+ <xs:attribute name="type" type="xs:string" use="optional"/>
64
+ </xs:extension>
65
+ </xs:simpleContent>
66
+ </xs:complexType>
67
+ <xs:complexType name="Text">
68
+ <xs:simpleContent>
69
+ <xs:extension base="xs:string">
70
+ <xs:attribute name="type" type="xs:string" use="optional"/>
71
+ </xs:extension>
72
+ </xs:simpleContent>
73
+ </xs:complexType>
74
+ <xs:complexType name="DateTime">
75
+ <xs:simpleContent>
76
+ <xs:extension base="xs:dateTime">
77
+ <xs:attribute name="type" type="xs:string" use="optional"/>
78
+ </xs:extension>
79
+ </xs:simpleContent>
80
+ </xs:complexType>
81
+ <xs:complexType name="Date">
82
+ <xs:simpleContent>
83
+ <xs:extension base="xs:date">
84
+ <xs:attribute name="type" type="xs:string" use="optional"/>
85
+ </xs:extension>
86
+ </xs:simpleContent>
87
+ </xs:complexType>
88
+ <xs:complexType name="Boolean">
89
+ <xs:simpleContent>
90
+ <xs:extension base="xs:boolean">
91
+ <xs:attribute name="type" type="xs:string" use="optional"/>
92
+ </xs:extension>
93
+ </xs:simpleContent>
94
+ </xs:complexType>
95
+ <xs:element name="#{model.xsd_generator.names.element_collection}" type="#{model.xsd_generator.names.collection_type}"/>
96
+ <xs:complexType name="#{model.xsd_generator.names.collection_type}">
97
+ <xs:sequence>
98
+ <xs:element name="#{model.xsd_generator.names.element}" type="#{model.xsd_generator.names.type}" minOccurs="0" maxOccurs="unbounded"/>
99
+ </xs:sequence>
100
+ <xs:attribute name="type" type="xs:string" fixed="array"/>
101
+ </xs:complexType>
102
+ <xs:complexType name="#{model.xsd_generator.names.type}">
103
+ <xs:all>
104
+ #{yield}
105
+ </xs:all>
106
+ </xs:complexType>
107
+ </xs:schema>
108
+ XML
109
+ sanitize_xml(output)
110
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: schematic
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.8
5
+ version: 0.1.2
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-27 00:00:00 Z
13
+ date: 2011-05-12 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -78,6 +78,17 @@ dependencies:
78
78
  version: "0"
79
79
  type: :development
80
80
  version_requirements: *id006
81
+ - !ruby/object:Gem::Dependency
82
+ name: autotest
83
+ prerelease: false
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id007
81
92
  description: Automatic XSD generation from ActiveRecord models
82
93
  email:
83
94
  - casecommons-dev@googlegroups.com
@@ -89,15 +100,34 @@ extra_rdoc_files: []
89
100
 
90
101
  files:
91
102
  - .gitignore
103
+ - .rspec
92
104
  - .rvmrc
93
105
  - Gemfile
94
106
  - LICENSE
95
107
  - README.rdoc
96
108
  - Rakefile
109
+ - TODO
97
110
  - lib/schematic.rb
111
+ - lib/schematic/generator/column.rb
112
+ - lib/schematic/generator/names.rb
113
+ - lib/schematic/generator/namespaces.rb
114
+ - lib/schematic/generator/restrictions/base.rb
115
+ - lib/schematic/generator/restrictions/enumeration.rb
116
+ - lib/schematic/generator/restrictions/length.rb
117
+ - lib/schematic/generator/restrictions/pattern.rb
118
+ - lib/schematic/generator/types.rb
119
+ - lib/schematic/generator/xsd.rb
98
120
  - lib/schematic/serializers/xsd.rb
99
121
  - lib/schematic/version.rb
100
122
  - schematic.gemspec
123
+ - spec/schematic/generator/restrictions/enumeration_spec.rb
124
+ - spec/schematic/generator/restrictions/length_spec.rb
125
+ - spec/schematic/generator/restrictions/pattern_spec.rb
126
+ - spec/schematic/serializers/xsd_extend_spec.rb
127
+ - spec/schematic/serializers/xsd_validation_presence_spec.rb
128
+ - spec/schematic/serializers/xsd_xsd_ignore_methods_spec.rb
129
+ - spec/schematic/serializers/xsd_xsd_methods_spec.rb
130
+ - spec/schematic/serializers/xsd_xsd_minimum_occurrences_for_spec.rb
101
131
  - spec/schematic_serializers_xsd_spec.rb
102
132
  - spec/spec_helper.rb
103
133
  - spec/xsd/XMLSchema.xsd
@@ -130,6 +160,14 @@ signing_key:
130
160
  specification_version: 3
131
161
  summary: Automatic XSD generation from ActiveRecord models
132
162
  test_files:
163
+ - spec/schematic/generator/restrictions/enumeration_spec.rb
164
+ - spec/schematic/generator/restrictions/length_spec.rb
165
+ - spec/schematic/generator/restrictions/pattern_spec.rb
166
+ - spec/schematic/serializers/xsd_extend_spec.rb
167
+ - spec/schematic/serializers/xsd_validation_presence_spec.rb
168
+ - spec/schematic/serializers/xsd_xsd_ignore_methods_spec.rb
169
+ - spec/schematic/serializers/xsd_xsd_methods_spec.rb
170
+ - spec/schematic/serializers/xsd_xsd_minimum_occurrences_for_spec.rb
133
171
  - spec/schematic_serializers_xsd_spec.rb
134
172
  - spec/spec_helper.rb
135
173
  - spec/xsd/XMLSchema.xsd