Class: Spectifly::Xsd::Builder
Instance Method Summary
collapse
#association_class, #associations, #custom_types, #field_class, #fields, from_path, #initialize, module_name, #native_types, #present_as, #root, #utilized_extended_type_fields, #utilized_extended_types
Instance Method Details
#build(xml = nil) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/spectifly/xsd/builder.rb', line 34
def build(xml = nil)
xml ||= ::Builder::XmlMarkup.new(:indent => 2)
xml.instruct! :xml, :version => '1.0', :encoding => 'UTF-8'
xml.xs :schema, 'xmlns:xs' => "http://www.w3.org/2001/XMLSchema", 'elementFormDefault' => "qualified" do
custom_types.each do |cust|
xml.xs :include, 'schemaLocation' => "#{cust}.xsd"
end
unless utilized_extended_types.empty?
xml.xs :include, 'schemaLocation' => "extended.xsd"
end
xml.xs :element,
:name => Spectifly::Support.camelize(root),
:type => root_type
build_type(xml)
end
end
|
#build_type(xml = nil) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/spectifly/xsd/builder.rb', line 13
def build_type(xml = nil)
xml ||= ::Builder::XmlMarkup.new(:indent => 2)
xml.xs 'complexType'.to_sym, :name => root_type do
xml.xs :sequence do
fields.each do |field|
field.to_xsd(xml)
end
associations.each do |association|
association.to_xsd(xml)
end
end
end
end
|
#types ⇒ Object
27
28
29
30
31
32
|
# File 'lib/spectifly/xsd/builder.rb', line 27
def types
[
fields.map(&:type) +
associations.select { |a| a.relationship !~ /belongs_to(_many)?/ }.map(&:type)
].flatten.compact.uniq
end
|