class Spectifly::Xsd::Association

Public Instance Methods

embedded_block() click to toggle source
# File lib/spectifly/xsd/association.rb, line 23
def embedded_block
  if description || example
    Proc.new { |el|
      if description || example
        el.xs :annotation do |ann|
          ann.xs :documentation, description if description
          ann.xs :documentation, "Example: #{example}" if example
        end
      end
    }
  end
end
name() click to toggle source
# File lib/spectifly/xsd/association.rb, line 4
def name
  Spectifly::Support.camelize(@field_name).gsub(/\W/, '')
end
to_xsd(builder = nil) click to toggle source
# File lib/spectifly/xsd/association.rb, line 8
def to_xsd(builder = nil)
  builder ||= ::Builder::XmlMarkup.new(:indent => 2)
  if relationship =~ /^belongs_to(_many)?/
    attributes['name'] = "#{name}Id"
    attributes['type'] = "xs:string"
  else
    attributes['name'] = name
    attributes['type'] = "#{Spectifly::Support.lower_camelize(type)}Type"
  end
  attributes['minOccurs'] = '0' unless required?
  attributes['maxOccurs'] = 'unbounded' if multiple?
  block = embedded_block
  builder.xs :element, attributes, &block
end