xml_schema_mapper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,67 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <xs:schema xmlns:tns="http://example.com/UserService/type/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
3
+ xmlns:com="http://example.com/common/"
4
+ targetNamespace="http://example.com/UserService/type/" version="1.0">
5
+
6
+ <xs:import namespace="http://example.com/common/" schemaLocation="common.xsd"/>
7
+
8
+ <xs:complexType name="Filter">
9
+ <xs:sequence>
10
+ <xs:element ref="tns:age"/>
11
+ <xs:element ref="tns:gender"/>
12
+ </xs:sequence>
13
+ </xs:complexType>
14
+
15
+ <xs:complexType name="GetFirstName">
16
+ <xs:annotation>
17
+ <xs:documentation>Foo Bar</xs:documentation>
18
+ </xs:annotation>
19
+ <xs:sequence>
20
+ <xs:element name="userIdentifier" type="xs:string" minOccurs="0"/>
21
+ <xs:element ref="tns:filter" minOccurs="0"/>
22
+ <xs:element name="isOut" type="com:ZONE"/>
23
+ <xs:element ref="com:zone"/>
24
+ <xs:element name="options" type="com:Options"/>
25
+ </xs:sequence>
26
+ <xs:attribute name="id" type="xs:string"/>
27
+ </xs:complexType>
28
+
29
+ <xs:complexType name="GetLastName">
30
+ <xs:annotation>
31
+ <xs:documentation>Foo Bar</xs:documentation>
32
+ </xs:annotation>
33
+ <xs:complexContent>
34
+ <xs:extension base="tns:GetFirstName">
35
+ <xs:sequence>
36
+ <xs:element name="userIdentifier2" type="xs:string"/>
37
+ <xs:choice>
38
+ <xs:element name="one" type="xs:string" minOccurs="1"/>
39
+ <xs:element name="two" type="xs:string" minOccurs="1"/>
40
+ </xs:choice>
41
+ </xs:sequence>
42
+ </xs:extension>
43
+ </xs:complexContent>
44
+ </xs:complexType>
45
+
46
+ <xs:element name="gender">
47
+ <xs:simpleType>
48
+ <xs:restriction base="xs:string">
49
+ <xs:enumeration value="male"/>
50
+ <xs:enumeration value="female"/>
51
+ </xs:restriction>
52
+ </xs:simpleType>
53
+ </xs:element>
54
+
55
+ <xs:element name="age">
56
+ <xs:simpleType>
57
+ <xs:restriction base="xs:integer">
58
+ <xs:minInclusive value="0"/>
59
+ <xs:maxInclusive value="100"/>
60
+ </xs:restriction>
61
+ </xs:simpleType>
62
+ </xs:element>
63
+
64
+ <xs:element name="filter" type="tns:Filter"/>
65
+ <xs:element name="getFirstName" type="tns:GetFirstName"/>
66
+ <xs:element name="getLastName" type="tns:GetLastName"/>
67
+ </xs:schema>
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <xs:schema xmlns:cm="http://example.com/common/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
3
+ targetNamespace="http://example.com/common/" version="1.0">
4
+
5
+ <xs:simpleType name="ZONE">
6
+ <xs:restriction base="xs:string">
7
+ <xs:enumeration value="a"/>
8
+ <xs:enumeration value="b"/>
9
+ <xs:enumeration value="c"/>
10
+ </xs:restriction>
11
+ </xs:simpleType>
12
+
13
+ <xs:complexType name="Options">
14
+ <xs:sequence>
15
+ <xs:element name="one" type="xs:string"/>
16
+ <xs:element name="two" type="xs:string"/>
17
+ </xs:sequence>
18
+ </xs:complexType>
19
+
20
+ <xs:element name="zone" type="cm:ZONE"/>
21
+ <xs:element name="options" type="cm:Options"/>
22
+
23
+ </xs:schema>
@@ -0,0 +1,13 @@
1
+ <getFirstName xmlns:tns="http://example.com/UserService/type/" xmlns:cm="http://example.com/common/">
2
+ <userIdentifier>001</userIdentifier>
3
+ <tns:filter>
4
+ <tns:age>50</tns:age>
5
+ <tns:gender>male</tns:gender>
6
+ </tns:filter>
7
+ <isOut>a</isOut>
8
+ <cm:zone>b</cm:zone>
9
+ <options>
10
+ <one>one</one>
11
+ <two>two</two>
12
+ </options>
13
+ </getFirstName>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <getFirstName xmlns:cm="http://example.com/common/" xmlns:tns="http://example.com/UserService/type/">
3
+ <userIdentifier>xoMPRY</userIdentifier>
4
+ <tns:filter>
5
+ <tns:age>94</tns:age>
6
+ <tns:gender>male</tns:gender>
7
+ </tns:filter>
8
+ <isOut>a</isOut>
9
+ <cm:zone>b</cm:zone>
10
+ <options>
11
+ <one>p6E58</one>
12
+ <two>Vm1sk87pkU0pE4EKKSY</two>
13
+ </options>
14
+ </getFirstName>
@@ -0,0 +1,23 @@
1
+ class ZONE
2
+ include XmlSchemaMapper
3
+ schema 'spec/fixtures/UserService.xsd'
4
+ type 'ZONE'
5
+ end
6
+
7
+ class Filter
8
+ include XmlSchemaMapper
9
+ schema 'spec/fixtures/UserService.xsd'
10
+ type 'Filter'
11
+ end
12
+
13
+ class Options
14
+ include XmlSchemaMapper
15
+ schema 'spec/fixtures/UserService.xsd'
16
+ type 'Options'
17
+ end
18
+
19
+ class GetFirstName
20
+ include XmlSchemaMapper
21
+ schema 'spec/fixtures/UserService.xsd'
22
+ type 'GetFirstName'
23
+ end
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+
3
+ describe "Parse XML" do
4
+
5
+ context "by GetFirstName" do
6
+ let(:xml) { File.read('spec/fixtures/instance1.xml') }
7
+
8
+ it "should parse with XmlSchemaMapper::Parser" do
9
+ XmlSchemaMapper::Parser.any_instance.should_receive(:parse).with(xml)
10
+ GetFirstName.parse(xml)
11
+ end
12
+
13
+ it "should return instance of GetFirstName" do
14
+ GetFirstName.parse(xml).should be_a GetFirstName
15
+ end
16
+
17
+ it "should lookup all elements" do
18
+ GetFirstName.elements.should_receive(:each)
19
+ GetFirstName.parse(xml)
20
+ end
21
+
22
+ context "its" do
23
+ subject { GetFirstName.parse(xml) }
24
+ its(:user_identifier) { should be_eql 'xoMPRY' }
25
+ its(:filter) { should be_a Filter }
26
+ its(:'filter.age') { should eql '94' }
27
+ its(:'filter.gender') { should eql 'male' }
28
+ its(:is_out) { should eql 'a' }
29
+ its(:zone) { should eql 'b' }
30
+ its(:options) { should be_a Options }
31
+ its(:'options.one') { should eql 'p6E58' }
32
+ its(:'options.two') { should eql 'Vm1sk87pkU0pE4EKKSY' }
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,24 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ $:.unshift './'
9
+ require "lib/xml_schema_mapper"
10
+ Dir['spec/fixtures/*.rb'].each do |f|
11
+ require f
12
+ end
13
+
14
+ RSpec.configure do |config|
15
+ config.treat_symbols_as_metadata_keys_with_true_values = true
16
+ config.run_all_when_everything_filtered = true
17
+ config.filter_run :focus
18
+
19
+ # Run specs in random order to surface order dependencies. If you find an
20
+ # order dependency and want to debug it, you can fix the order by providing
21
+ # the seed, which is printed after each run.
22
+ # --seed 1234
23
+ #config.order = 'random'
24
+ end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ describe XmlSchemaMapper do
4
+
5
+ context "valid mapping" do
6
+ subject { GetFirstName.new }
7
+
8
+ it "should be XmlSchemaMapper" do
9
+ subject.should be_a XmlSchemaMapper
10
+ end
11
+
12
+ its(:_schema) { should be_a LibXML::XML::Schema }
13
+ its(:_type) { should be_a LibXML::XML::Schema::Type }
14
+ its(:'_type.name') { should eql 'GetFirstName' }
15
+ its(:'_type.namespace') { should eql 'http://example.com/UserService/type/' }
16
+
17
+ its(:element_names) { should eql %w(userIdentifier filter isOut zone options) }
18
+ end
19
+
20
+ context "not valid mapping" do
21
+ let(:klass) { Class.new { include XmlSchemaMapper } }
22
+
23
+ it "should raise error" do
24
+ expect { klass.type "Bla" }.to raise_error %Q{call "schema 'path/to/your/File.xsd'" before calling "type"}
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/xml_schema_mapper/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Anton Sozontov"]
6
+ gem.email = ["a.sozontov@gmail.com"]
7
+ gem.description = %q{XMLSchemaMapper is your way to use XSD for XML}
8
+ gem.summary = %q{Bind you classes to xsd schema types and parse/build xml}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "xml_schema_mapper"
15
+ gem.require_paths = ["lib"]
16
+
17
+ gem.add_development_dependency "rspec"
18
+ gem.add_development_dependency "guard-rspec"
19
+
20
+ gem.add_runtime_dependency "activesupport"
21
+ gem.add_runtime_dependency "nokogiri"
22
+ gem.add_runtime_dependency "thor"
23
+ gem.add_runtime_dependency "virtus"
24
+
25
+ gem.version = XmlSchemaMapper::VERSION
26
+ end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xml_schema_mapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Anton Sozontov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: guard-rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: activesupport
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: nokogiri
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: thor
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: virtus
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: XMLSchemaMapper is your way to use XSD for XML
111
+ email:
112
+ - a.sozontov@gmail.com
113
+ executables:
114
+ - xml_schema_mapper
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .idea/.rakeTasks
120
+ - .idea/encodings.xml
121
+ - .idea/misc.xml
122
+ - .idea/modules.xml
123
+ - .idea/scopes/scope_settings.xml
124
+ - .idea/vcs.xml
125
+ - .idea/workspace.xml
126
+ - .idea/xml_schema_mapper.iml
127
+ - .rspec
128
+ - Gemfile
129
+ - Guardfile
130
+ - LICENSE
131
+ - README.md
132
+ - Rakefile
133
+ - bin/xml_schema_mapper
134
+ - lib/thor/templates/converter_class.erb
135
+ - lib/thor/templates/converter_spec.erb
136
+ - lib/thor/templates/mapper_class.erb
137
+ - lib/thor/templates/mapper_spec.erb
138
+ - lib/thor/xsd_mappers.rb
139
+ - lib/xml_schema_mapper.rb
140
+ - lib/xml_schema_mapper/builder.rb
141
+ - lib/xml_schema_mapper/element.rb
142
+ - lib/xml_schema_mapper/parser.rb
143
+ - lib/xml_schema_mapper/version.rb
144
+ - spec/build_xml_spec.rb
145
+ - spec/builder_spec.rb
146
+ - spec/element_spec.rb
147
+ - spec/fixtures/LocalUserService.xsd
148
+ - spec/fixtures/UserService.xsd
149
+ - spec/fixtures/common.xsd
150
+ - spec/fixtures/get_first_name.xml
151
+ - spec/fixtures/instance1.xml
152
+ - spec/fixtures/user_service.rb
153
+ - spec/parse_xml_spec.rb
154
+ - spec/spec_helper.rb
155
+ - spec/xml_schema_mapper_spec.rb
156
+ - xml_schema_mapper.gemspec
157
+ homepage: ''
158
+ licenses: []
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ none: false
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ! '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ requirements: []
176
+ rubyforge_project:
177
+ rubygems_version: 1.8.23
178
+ signing_key:
179
+ specification_version: 3
180
+ summary: Bind you classes to xsd schema types and parse/build xml
181
+ test_files:
182
+ - spec/build_xml_spec.rb
183
+ - spec/builder_spec.rb
184
+ - spec/element_spec.rb
185
+ - spec/fixtures/LocalUserService.xsd
186
+ - spec/fixtures/UserService.xsd
187
+ - spec/fixtures/common.xsd
188
+ - spec/fixtures/get_first_name.xml
189
+ - spec/fixtures/instance1.xml
190
+ - spec/fixtures/user_service.rb
191
+ - spec/parse_xml_spec.rb
192
+ - spec/spec_helper.rb
193
+ - spec/xml_schema_mapper_spec.rb