Sha256: 422a9368e7e47381f226341bc050ad8f96f5e294e39bbda4f0b872893bb6206c
Contents?: true
Size: 1.49 KB
Versions: 2
Compression:
Stored size: 1.49 KB
Contents
require 'builder' require_relative 'field' require_relative 'association' require_relative 'types' module Spectifly module Xsd class Builder < Spectifly::Base::Builder def root_type Spectifly::Support.lower_camelize("#{root}Type") end 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 def types [ fields.map(&:type) + associations.select { |a| a.relationship != 'belongs_to' }.map(&:type) ].flatten.compact.uniq end 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 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
spectifly-0.0.7 | lib/spectifly/xsd/builder.rb |
spectifly-0.0.6 | lib/spectifly/xsd/builder.rb |